Possible Duplicates:
confused with the scope in c#
C# Variable Scoping
I am curious about the design considerations behind the scope of variables which are declared in the initialization part of for-loops (etc). Such variables neither seem to be in-scope or out-of scope or am I missing something? Why is this and when is this desired? Ie:
for (int i = 0; i < 10; i++)
{
}
i = 12; //CS0103: The name 'i' does not exist in the current context
int i = 13; //CS0136: A local variable named 'i' cannot be declared in this scope
//because it would give a different meaning to 'i', which is already
//used in a 'child' scope to denote something else