Compiler Error CS0136
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/child' scope to denote something else
A variable declaration hides another declaration that would otherwise be in scope. Rename the variable that is declared on the line that generated CS0136.
Example
The following sample generates CS0136:
// CS0136.cs
namespace MyNamespace
{
public class MyClass
{
public static void Main()
{
int i = 0;
{
char i = 'a'; // CS0136, hides int i
}
i++;
}
}
}
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.