void 计算()
{
Calc clac;//声明一个类
switch (cbChar.SelectedItem.ToString())
{
case "+":
clac = new CalcAddWay();
clac.Num1 = int.Parse(tbNum1.Text);
clac.Num2 = int.Parse(tbNum2.Text);
tbResult.Text = clac.CalcResult().ToString();
break;
case "-":
clac = new CalcSubWay();
break;
case "*":
clac = new CalcChengWay();
break;
default:
clac = new CalcChuWay();
break;
}
clac.Num1 = int.Parse(tbNum1.Text);
//如果不写默认的default方法,下面此处会报错:使用了未赋值的局部变量(也就是clac)
clac.Num2 = int.Parse(tbNum2.Text);
tbResult.Text = clac.CalcResult().ToString();
}