This is because it is just a delegate, and it starts when you call it, and at the time it is called, all actions have the last value that was set for i , whereas in the case of the foreach loop, a local copy of the value, so each action has its own value which makes printing 0-9.
In the first example, the value of i is evaluated the first time the delegate is called in the foreach loop, and at that time i has 10 , and in the second example, you store the value in local, which simulates the same behavior that is performed using the foreach loop, since the foreach loop also creates copy value.
you can also read this explanation by Jon Skeet , and there he links with 2 eric-lipper messages to help you more.
source share