Compiler Error CS0135
'declaration1' conflicts with the declaration 'declaration2'
The compiler does not allow hiding names, which commonly leads to logic errors in your code.
The following sample generates CS0135:
// CS0135.cs
public class MyClass2
{
public static int i = 0;
public static void Main()
{
{
int i = 4;
i++;
}
i = 0; // CS0135
}
}
From the C# Language Specification, Section 7.5.2.1:
For each occurrence of a given identifier as a simple-name in an expression or declarator, within the local variable declaration space (§3.3) immediately enclosing that occurrence, every other occurrence of the same identifier as a simple-name in an expression or declarator must refer to the same entity. This rule ensures that the meaning of a name is always the same within a given block, switch block, for-, foreach- or using-statement, or anonymous function.