不能隐式地将类型“;”转换为“;”Bool
本文关键字:Bool 转换 类型 不能 | 更新日期: 2023-09-27 18:01:24
int ValueOne, ValueTwo, Numchar, Total;
Console.WriteLine("This Is A Program For doing any Of the four mathematical Proccesses");
Console.WriteLine("You can Add , substract , Divide And Multiply");
Console.WriteLine("When Asked Please Type The Values Or The Proccesses You Want.");
Console.WriteLine("Please Type The First Value");
ValueOne = Convert.ToInt32((Console.ReadLine()));
Console.WriteLine("Please Type The Second Value");
ValueTwo = Convert.ToInt32((Console.ReadLine()));
Console.WriteLine("Please Enter The Number Of The Proccess/Character You Want Meaning That (1 = +) , (2 = -) , (3 = *) , (4 = /)");
Numchar = Convert.ToInt32((Console.ReadLine()));
if ((Numchar) = 1)
Total = ValueOne + ValueTwo;
if ((Numchar) = 2)
Total = ValueOne + ValueTwo;
if ((Numchar) = 3
Total = ValueOne * ValueTwo;
if ((Numchar) = 4
Total = ValueOne / ValueTwo;
这是一个使用c#的控制台应用程序,我的错误是:"If ((NumChar) = (number)"我是visual studio的初学者,我刚刚开始学习
if ((Numchar) = 1)
应该if (Numchar == 1)
=用于赋值
==用于比较值
编辑:正如注释所指出的,你在第三和第四个if语句中遗漏了右括号if ((Numchar) = 3
应该if (Numchar = 3)
并去掉Numchar周围的括号,它们是没有意义的
使用==进行比较。例如:
if ((Numchar) == 2)
Total = ValueOne + ValueTwo;
当您使用单个相等时,您将值赋给Numchar,并且返回新值(在本例中为int)
看起来你可能习惯了VB(基于你的变量名等)。Telerik有一个很好的VB到c#代码转换器,你可以用它来检查你的结果,在这里:
http://converter.telerik.com/你是在赋值,而不是比较它。使用==
进行比较