我想比較兩個文本框,看看他們是空的,但我得到一個異常錯誤:如何比較兩個文本框?
Input string was not in a correct format
代碼:
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);
}
}
'txttea.Text'和'txtcoffee.Text'的值是什麼? –
檢查你的txttea.Text和txtCoffee.Text是否是數字。 –
iswanto san:它的一個數字 – raneena