gpt4 book ai didi

c# - 类、结构或接口(interface)成员声明中的标记无效

转载 作者:行者123 更新时间:2023-12-02 10:45:55 29 4
gpt4 key购买 nike

我的代码有问题:

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): error CS1513: } expected
Mm.cs(12,13): error CS1519: Invalid token 'if' in class, struct, or interface member declaration
Mm.cs(12,24): error CS1519: Invalid token '==' in class, struct, or interface member declaration
Mm.cs(14,37): error CS1519: Invalid token '(' in class, struct, or interface member declaration

最佳答案

在您的Main() 内函数,局部变量LogInputPassInput必须在没有 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 .

关于c# - 类、结构或接口(interface)成员声明中的标记无效,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63641912/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com