编译C#代码时出现许多错误
我正在学习C#,我试着做一个简单的终端游戏。所以,当我试图编译它时,它给出了6个错误 代码是:编译C#代码时出现许多错误,c#,C#,我正在学习C#,我试着做一个简单的终端游戏。所以,当我试图编译它时,它给出了6个错误 代码是: { Console.WriteLine("Hello, what is your name? : "); string name = Console.ReadLine(); //Lets you enter the name Console.WriteLine($"Hello, {name}! What should I do? \n Type help for lis
{
Console.WriteLine("Hello, what is your name? : ");
string name = Console.ReadLine(); //Lets you enter the name
Console.WriteLine($"Hello, {name}! What should I do? \n Type help for list of commands);
Console.ReadKey();
string command = Console.ReadLine();
if(command == "help")
Console.WriteLine("The only command for now is \"Market\"");
else if(command == "Market")
Console.WriteLine("You're now at the market");
else
Console.WriteLine("Sorry, I didn't understand you!");
Console.ReadKey();
}
以下是终端对它的描述:
ReadLine.cs(24,70): error CS1525: Unexpected symbol `The'
ReadLine.cs(24,100): error CS1056: Unexpected character `\0022'
ReadLine.cs(24,102): error CS1056: Unexpected character `\0022'
ReadLine.cs(24,105): error CS1010: Newline in constant
ReadLine.cs(26,39): error CS1525: Unexpected symbol `)'
ReadLine.cs(29,12): error CS1525: Unexpected symbol `else'
一行缺少结束引号,可能导致其他错误:
Console.WriteLine($"Hello, {name}! What should I do? \n Type help for list of commands);
请尝试以下方法:
Console.WriteLine($"Hello, {name}! What should I do? \n Type help for list of commands");
如果您遇到了一个对您来说毫无意义的错误,并且它所指的行似乎是正确的,这通常是前一行出现错误的迹象。查看报告问题的行上方 如果你仍然看不到,试着注释几行来缩小问题的范围
缺少引号和/或分号往往是罪魁祸首。此外@doctorlove还说。。。通常情况下,一个错误会产生多个错误。修复一个,所有(或多个)都会消失。