Why does a local variable inside a foreach loop conflict with a variable declared outside the loop?
Given this code:
List<string> things = new List<string>();
foreach (string thing in things)
{
string foo = thing.ToUpper();
}
string foo = String.Empty;
Why does the compiler complain that foo is declared twice? Surely the instance declared in the foreach loop is only valid within the loop?
+3
source to share