It's written in the C# standard, around page 88 (110 real page):
[Note: As specified above, the declaration space of a block cannot share names with the declaration spaces of any nested blocks. Thus, in the following example, the F and G methods result in a compile-time error because the name i is declared in the outer block and cannot be redeclared in the inner block. However, the H and I methods are valid since the two i’s are declared in separate non-nested blocks.
class A
{
void F() {
int i = 0;
if (true) {
int i = 1;
}
}
void G() {
if (true) {
int i = 0;
}
int i = 1;
}
void H() {
if (true) {
int i = 0;
}
if (true) {
int i = 1;
}
}
void I() {
for (int i = 0; i < 10; i++) H(); for (int i = 0; i < 10; i++) H(); } }
end note]
I hate compilers that impose stupid constrains.
1 comment:
This just means the bug is not in the implementation, but rather in the specification.
Post a Comment