我在Visual Studio 2008中收到以下错误:
Error 1 A local variable named 'i' cannot be declared in this scope because it would give a different meaning to 'i', which is already used in a 'child' scope to denote something else
这是我的代码:
for (int i = 0; i < 3; i++)
{
string str = "";
}
int i = 0; // scope error
string str = ""; // no scope error
Run Code Online (Sandbox Code Playgroud)
我知道str
一旦循环终止就不再存在,但我也认为范围i
也局限于for
循环.
那么i
与在for
循环之外声明的变量具有相同的范围吗? …