You cannot play it because you are changing the version of the .Net framework, but not the compiler. You always use C # v5.0, which fixes the problem for foreach loops. You can see the problem with for loops:
Action[] actions = new Action[3]; int i = 0; for (int j = 0; j < "abc".Length; j++) actions[i++] = () => Console.Write("abc"[j]); for (int j = 0; j < 3; j++) { actions[j](); } foreach (Action a in actions) a(); Console.ReadLine();
To use the old compiler, you need an old version of VS. In this case, to see your code break with foreach , you need to test it in VS 2010 (I did it locally).
You might want to try changing the language version of the compiler (as suggested by xanatos in the comments), but not using the old compiler. It uses the same compiler, but restricts the use of certain functions:
Because each version of the C # compiler contains extensions for the language specification, /langversion does not give you the equivalent functionality of an earlier version of the compiler.
From / langversion (C # compiler options)
source share