我正在尝试比较两个文本框以查看它们是否为空,但出现异常错误:
输入字符串的格式不正确
代码:
private void btncalc_Click(object sender, EventArgs e)
{
try
{
int ina= int.Parse(txttea.Text);
int inb= int.Parse(txtcoffee.Text);
int inc = 0, ind = 0;
if (this.txttea.Text == "" && this.txtcoffee.Text == "") // this not working
{
MessageBox.Show("select a item");
txttea.Focus();
}
if (cbxwithoutsugar.Checked)
{
inc = (ina * 20);
}
else
{
inc = (ina * 8);
}
if (cbxcoldcoffee.Checked)
{
ind = (inb * 10);
}
else
{
ind = (inb * 5);
}
txtamount.Text = (Convert.ToInt32(inc) + Convert.ToInt32(ind)).ToString();
}
catch (Exception a)
{
MessageBox.Show(a.Message);
}
}