我只是学习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 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();
}
Run Code Online (Sandbox Code Playgroud)
这就是终端所说的:
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'
Run Code Online (Sandbox Code Playgroud)
一行有一个缺少的收盘报价,并且看起来导致其他错误:
Console.WriteLine($"Hello, {name}! What should I do? \n Type help for list of commands);
Run Code Online (Sandbox Code Playgroud)
试试这个:
Console.WriteLine($"Hello, {name}! What should I do? \n Type help for list of commands");
Run Code Online (Sandbox Code Playgroud)
如果您收到一个对您没有意义的错误,并且它所指的行似乎是正确的,这通常表示前一行有错误.看看报告问题的线条上方.
如果您仍然看不到它,请尝试注释掉几行以缩小问题范围.
缺少引号和/或分号通常是罪魁祸首.
| 归档时间: |
|
| 查看次数: |
95 次 |
| 最近记录: |