gpt4 book ai didi

c# - 错误CS1525为什么会发生?

转载 作者:行者123 更新时间:2023-12-02 11:13:17 28 4
gpt4 key购买 nike

我不知道为什么,但是当我尝试编译下一个代码时,我得到错误CS1525,并且每个while命令结尾的每个)都被标记为错误:

static void PrintArray(string[] arr)
{
int i, sum = 0, subb = 0, pow, x;
char opper;
Console.WriteLine("how many numbers does your calculation have?");
i = Convert.ToInt16(Console.ReadLine());
arr = new string[i];
for (i = 0; i < arr.Length; i++)
{
Console.WriteLine("enter num {0}" + i);
arr[i] = Console.ReadLine();
Console.WriteLine("arr[{0}] = {1}" + i, arr[i]);
}
Console.WriteLine("what do you want to do?");
opper = Convert.ToChar(Console.ReadLine());
while (opper = +)
{
for (i = 0; i < arr.Length; i++)
{
sum = sum + Convert.ToInt16(arr[i]);
}
Console.WriteLine("your sum is " + sum);
}
while (opper = -)
{
for (i = 0; i < arr.Length; i++)
{
subb = subb + Convert.ToInt16(arr[i]);
}
Console.WriteLine("your subb is" + subb);
}
while (opper = *)
{
pow = Convert.ToInt16(arr[0]);
for (i = 1; i < arr.Length; i++)
{
pow = pow * Convert.ToInt16(arr[i]);
}
Console.WriteLine("the resolt is " + pow);
}
while (opper = &)
{
x = Convert.ToInt16(arr[i]);
for (i = 0; i < arr.Length; i++)
{
x = x / Convert.ToInt16(arr[i]);
}
Console.WriteLine("your resolt is " + x);
}
Console.ReadKey();
}

如果有人最终可以向我解释这一点,我将感到非常高兴。

最佳答案

给定线(例如)

opper = Convert.ToChar(Console.ReadLine());
while (opper = +)

您似乎正在尝试将字符输入与运算符进行比较。您需要将赋值运算符更改为比较运算符,然后将该字符与另一个字符进行比较,如下所示:
opper = Convert.ToChar(Console.ReadLine());
while (opper == '+')

关于c# - 错误CS1525为什么会发生?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39839599/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com