我在equals按钮上有错误.
private void button25_Click(object sender, EventArgs e) { lblShowOp.Text = ""; switch (operation) { case "+": tb1.Text = (results + Double.Parse(tb1.Text).ToString()); break; case "-": // operator '-' cannot be applied to operands of type 'double and string' tb1.Text = (results - Double.Parse(tb1.Text).ToString()); break; case "*": // operator '*' cannot be applied to operands of type 'double and string' tb1.Text = (results * Double.Parse(tb1.Text).ToString()); break; case "/": // operator '/' cannot be applied to operands of type 'double and string' tb1.Text = (results / Double.Parse(tb1.Text).ToString()); break; } }
Charles Mage.. 8
Double.Parse(tb1.Text).ToString()
将解析为一个数字然后转换回字符串.
根据错误消息,您不能向字符串添加数字(或乘以,减去等).
你的括号在错误的地方.改变一下:
tb1.Text = (results + Double.Parse(tb1.Text).ToString());
对此:
tb1.Text = (results + Double.Parse(tb1.Text)).ToString();
并且对于其他每个人都是如此.
Double.Parse(tb1.Text).ToString()
将解析为一个数字然后转换回字符串.
根据错误消息,您不能向字符串添加数字(或乘以,减去等).
你的括号在错误的地方.改变一下:
tb1.Text = (results + Double.Parse(tb1.Text).ToString());
对此:
tb1.Text = (results + Double.Parse(tb1.Text)).ToString();
并且对于其他每个人都是如此.