【问题标题】:Invalid token in class, struct, or interface member declaration类、结构或接口成员声明中的标记无效
【发布时间】:2020-08-28 23:11:55
【问题描述】:

我的代码有问题:

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

【问题讨论】:

  • 将您的代码发布为code text,而不是图片。
  • 我无法做到这一点,因为它主要是代码,我无法发送它,
  • 只需将图像中显示的文本复制并粘贴到此问题中即可。如果需要更多文本,请使用更多非代码词更好地描述您的问题。
  • 已修复。对不起,我是新来的。

标签: c# compiler-errors


【解决方案1】:

在您的 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

【讨论】:

    猜你喜欢
    • 2013-01-02
    • 1970-01-01
    • 1970-01-01
    • 2014-04-07
    • 2014-06-22
    • 2016-07-10
    • 1970-01-01
    • 2012-06-19
    • 2014-02-02
    相关资源
    最近更新 更多