![](/img/trans.png)
[英]Invalid token ';' in class, struct, or interface member declaration
[英]Invalid token in class, struct, or interface member declaration
我的代碼有問題:
using System;
using System.Threading;
namespace popo
{
public class Human
{
public static void Main()
{
Console.Write("Login: ");
public string LogInput = Console.Read();
if(LogInput=="ADMIN")
{
System.Console.Write("Password: ");
public string PassInput = Console.Read();
if(PassInput == "ADMIN")
{
System.Console.Write("L");
Thread.Sleep(1000);
System.Console.Write("O");
Thread.Sleep(1000);
System.Console.Write("G");
Thread.Sleep(1000);
System.Console.Write("G");
Thread.Sleep(1000);
System.Console.Write("E");
Thread.Sleep(1000);
System.Console.Write("D");
}
}
}
}
}
當我試圖編譯它時,編譯器說:
Mm.cs(10,38): 錯誤 CS1513: } 預期
Mm.cs(12,13):錯誤 CS1519:類、結構或接口成員聲明中的無效標記“if”
Mm.cs(12,24):錯誤 CS1519:類、結構或接口成員聲明中的無效標記“==”
Mm.cs(14,37): error CS1519: Invalid token '(' in class, struct, or interface member declaration
在Main()
函數中,局部變量LogInput
和PassInput
必須在沒有public
關鍵字的情況下聲明。 另外,將Console.Read()
替換為Console.ReadLine()
。 因此,您的Main()
應如下所示:
public static void Main()
{
Console.Write("Login: ");
string LogInput = Console.ReadLine();
if(LogInput=="ADMIN")
{
System.Console.Write("Password: ");
string PassInput = Console.ReadLine();
if(PassInput == "ADMIN")
{
// further as you had it...
}
}
}
檢查這個DotNetFiddle 。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.