为什么在我的C# .NET 7脚本中,VS Code中的分号是红色的?

huangapple go评论58阅读模式
英文:

Why semicolon is red in my c# dotnet 7 script in vscode?

问题

[Screenshot of error message in VSCode](https://i.stack.imgur.com/5Kbzn.png)

```csharp
using System;
namespace CodeWarTests
{
    class Program 
    {         
        static void Main(string[] args)
        {
            Console.WriteLine("Hello World!");
            private int test = 0;
        }
    }
}

I'm expecting not red semicolon.


<details>
<summary>英文:</summary>

[Screenshot of error message in VSCode](https://i.stack.imgur.com/5Kbzn.png)

```csharp
using System;
namespace CodeWarTests
{
    class Program 
    {         
        static void Main(string[] args)
        {
            Console.WriteLine(&quot;Hello World!&quot;);
            private int test = 0;
        }
    }

}

I'm expecting not red semicolon.

答案1

得分: 3

The private qualifier is for members of the class, not for local variables. It shows that it therefore expected a } after the ; in your line 10.

因此,以下版本不应显示任何错误:

using System;
namespace CodeWarTests
{
    class Program 
    {         
        static void Main(string[] args)
        {
            Console.WriteLine("Hello World!");
            int test = 0;
        }
    }
}
英文:

The private qualifier is for members of the class, not for local variables. It shows that it therefore expected a } after the ; in your line 10.

https://learn.microsoft.com/en-us/dotnet/csharp/misc/cs1513

Therefore the following version should not show any error:

using System;
namespace CodeWarTests
{
    class Program 
    {         
        static void Main(string[] args)
        {
            Console.WriteLine(&quot;Hello World!&quot;);
            int test = 0;
        }
    }

}

huangapple
  • 本文由 发表于 2023年6月29日 23:04:27
  • 转载请务必保留本文链接:https://go.coder-hub.com/76582305.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定