[From the SDK docs] "A local variable named 'var' cannot be declared in this scope because it would give a different meaning to 'var', which is already used in a 'parent or current' scope to denote something else".
although you can do this legally: void Method() { { int decl; } { int decl; } } because neither variable is in the parent scope of the other. Jim > -----Original Message----- > From: Jon Jagger [mailto:[EMAIL PROTECTED]] > Sent: 17 May 2002 15:06 > To: [EMAIL PROTECTED] > Subject: [DOTNET] Is this program conforming? > > > I've been trying to track down why the Microsoft C# compiler fails to > compile the following program: > > class T > { > int decl; // of a field > > void Method() > { > decl++; > > { > int decl; // of a local variable > } > } > } > > The closest I can get is 14.5.2.1 Invariant meaning in > blocks, which states > > "For each occurence of a simple-name in an expression, every other > occurence of the same identifier as a simple-name in an > expression within > the immediately enclosing block or switch-block must refer to the same > entity." > > However, I don't think the program violates this constraint > because the > second occurence of decl is not in an expression (its in a > declarator). > > Have I missed something or is the compiler being a tad over zealous? > > Thanks > Jon Jagger > > You can read messages from the DOTNET archive, unsubscribe > from DOTNET, or > subscribe to other DevelopMentor lists at http://discuss.develop.com. > You can read messages from the DOTNET archive, unsubscribe from DOTNET, or subscribe to other DevelopMentor lists at http://discuss.develop.com.