Wednesday, January 20, 2010

C# - Variable xxx is already defined in this scope

WTF!?

after coming back from holidays I had no mood/time to write anything, so let's change it with a technical stuff. I was writing a C# code (C# is a programming language copyed from Java) and found a strange behaviour of variable scopes unique to this language. Create a for cycle, define a variable inside, define the same variable after the for cycle and an error is shown:

for (int i = 0; i < 10; i++)
{
int xxx = 1;
}

int xxx = 0; //ERROR!

Variable xxx is already defined in this scope.

What scope, that's a child scope and has nothing to do with this one. Arggg.

:D

No comments: