无法将类型 "int" 隐式转换为 Bool
Cannot implicitly convert type "int" into Bool
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) == 2)
Total = ValueOne + ValueTwo;
当您使用单个等于时,您是在为 Numchar 赋值,然后返回新值(在本例中为 int)
看起来您可能习惯于 VB(基于您的变量名称等)。 Telerik 有一个很好的 VB 到 C# 代码转换器,您可以使用它来仔细检查您的结果,这里:
if ((Numchar) = 1)
应该是
if (Numchar == 1)
=用于赋值
== 用于比较值
编辑:正如评论所指出的,您在第 3 个和第 4 个 if 语句中漏掉了右括号
if ((Numchar) = 3
应该是
if (Numchar = 3)
并去掉 Numchar 周围的括号,它们毫无意义
您正在分配一个值,而不是比较它。使用==
进行比较
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) == 2)
Total = ValueOne + ValueTwo;
当您使用单个等于时,您是在为 Numchar 赋值,然后返回新值(在本例中为 int)
看起来您可能习惯于 VB(基于您的变量名称等)。 Telerik 有一个很好的 VB 到 C# 代码转换器,您可以使用它来仔细检查您的结果,这里:
if ((Numchar) = 1)
应该是
if (Numchar == 1)
=用于赋值
== 用于比较值
编辑:正如评论所指出的,您在第 3 个和第 4 个 if 语句中漏掉了右括号
if ((Numchar) = 3
应该是
if (Numchar = 3)
并去掉 Numchar 周围的括号,它们毫无意义
您正在分配一个值,而不是比较它。使用==
进行比较