I'm confused why is there compiler error CS0136 "A local or parameter named 'a' cannot be declared in this scope because that name is used in an enclosing local scope to define a local or parameter" in loops of that kind? Isn't first a enclosed inside the loop?
static void Main(string[] args)
{
for (int i = 0; i < 10; i++)
{
int a = 0;
}
int a = 1;
}
If not, why is there compiler Error CS0841 Cannot use local variable 'b' before it is declared in this variant
static void Main(string[] args)
{
for (int i = 0; i < 10; i++)
{
int a = b;
}
int b = 1;
}
Is there any contradiction here and why is this restriction made for?