为什么如果我用 C# 写这个:
for(int myVar = 0; myVar<10; myVar++)
{
//do something here
}
//then, if I try:
int myVar = 8;
//I get some error that the variable is already declared.
//but if I try:
Console.WriteLine(myVar);
//then I get the error that the variable is not declared.
我最常说的有点令人困惑。有谁知道为什么 C# 编译器会这样做?