问题解决了,大家都有道理,偶也学了不少东西
下面是一种方法的代码:
private void button1_Click(object sender, EventArgs e)
{
int num1, num2;
double result;
if (String.IsNullOrEmpty(textBox1.Text) || String.IsNullOrEmpty(textBox2.Text))
{
MessageBox.Show("输入不完整!");
return;
}
try
{
num1 = Convert.ToInt32(textBox1.Text);
num2 = Convert.ToInt32(textBox2.Text);
result = checked(num1 + num2);
textBox3.Text = Convert.ToString(result);
}
catch (OverflowException)
{
textBox3.Text = "加法溢出!";
}
}
下面是一种方法的代码:
private void button1_Click(object sender, EventArgs e)
{
int num1, num2;
double result;
if (String.IsNullOrEmpty(textBox1.Text) || String.IsNullOrEmpty(textBox2.Text))
{
MessageBox.Show("输入不完整!");
return;
}
try
{
num1 = Convert.ToInt32(textBox1.Text);
num2 = Convert.ToInt32(textBox2.Text);
result = checked(num1 + num2);
textBox3.Text = Convert.ToString(result);
}
catch (OverflowException)
{
textBox3.Text = "加法溢出!";
}
}
责人之心责己 宽己之心宽人