The foreach identifier and closures
Edit: this all changes in C# 5, with a change to where the variable is defined (in the eyes of the compiler). From C# 5 onwards, they are the same. Before C#5 The second is safe; the first isn’t. With foreach, the variable is declared outside the loop – i.e. Foo f; while(iterator.MoveNext()) { f … Read more