可能重複:
C#, Operator ‘*’ cannot be applied to operands of type ‘double’ and ‘decimal’倍增文本框的值
嗨,我想乘上在文本框中插入的數值,但我得到錯誤。這是我的代碼。
decimal num1, num2;
if(decimal.TryParse(textBox1.Text, out num1)
&& decimal.TryParse(textBox2.Text, out num2)){
decimal ans = num1 * 0.20 + num2 * 0.20;
Label1.Text = ans.ToString();
}else{
MessageBox.Show("Please Put a number!! ");
}
我有錯誤的「ans」請幫助我。這是我的錯誤「運算符*不能應用於'decimal'和double類型的操作數;」
周杰倫,什麼是錯誤信息? – Zbigniew
運算符*不能應用於'decimal'和double類型的操作數; – Jay
然後,這是[http://stackoverflow.com/questions/363706/c-operator-cannot-be-applied-to-operands-of-type-double-and-decimal](http:// stackoverflow.com/questions/363706/c-operator-cannot-be-applied-to-operands-of-type-double-and-decimal) – Zbigniew