Not sure if this is because the C# compiler is extra picky, but I try to do this in C#:
public static void Main()
{
bool result = true; // some dummy value
if(result)
{
int x = 5;
Console.WriteLine(x);
}
int x = 10;
Console.WriteLine(x);
}
The compiler complains that the variable name "x" is already being used:
A local variable named 'x' cannot be declared in this scope because it would give a different meaning to 'x', which is already used in a 'child' scope to denote something else.
And I understand that it thinks it's a scope issue, but why does it think that?
If I reproduce the same code in Java, there are no problems.