英文:
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("Hello World!");
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("Hello World!");
int test = 0;
}
}
}
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论