I have a very simple use case:
class Program
{
private static void Test()
{
{
const bool thing = false;
}
bool thing = true;
}
static void Main()
{
Console.WriteLine("Hello, World!");
}
}
I'm getting this error when I compile this code:
main.cs(12,14): error CS0136: A local variable named 'thing' cannot be declared in this scope because it would give a different meaning to 'thing', which is already used in a 'child' scope to denote something else
Why does the second declaration of thing
interfere with the first? I come from a heavy C++ background, so I was expecting this to be semantically the same: The two are separated by scope. In my mind, the const bool thing
should not be available to the outer scope. What am I missing here?
Note that I did my best to google this, but unfortunately I don't know the correct terms to search for, so I've been unable to find an example of someone else trying this.
Note I'm using C# version 8 on .NET Framework 4.8.