[英]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.