2017-06-19 83 views
0

我剛剛學習C#,並試圖製作一個簡單的終端遊戲。所以,當我試圖編譯它時,它會給出6個錯誤。編譯C#代碼時出現很多錯誤

的代碼是:

{ 
    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' 

回答

7

一行缺少一個右引號,並期待導致其他錯誤回報:

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"); 

如果您收到一條對您沒有意義的錯誤,並且它引用的行看起來是正確的,那麼這通常是前一行中出現錯誤的標誌。看看報告問題的上方。

如果您仍然看不到它,請嘗試註釋幾行以縮小問題範圍。

缺少引號和/或分號通常是罪魁禍首。

+1

並添加到@doctorlove所說的...通常,單個錯誤會產生多個錯誤。修復一個,所有(或許多)都會消失。 –