I have a function that creates a bunch of toolstripitems based on a list of strings. I create those click events on the toolstripitem as an anonymous function, and I use the string value in my anonymous function.
It is a .NET 4 application.
When I compile that on a VS2010 SP1 (10.0.40219.1 SP1Rel), the string value that is used is the one that was set during the last pass through the foreach loop.
When I compile that on a VS2012 U1 (11.0.51106.01 Update 1), the string value that is used is the one that was set during the current enumeration on the list in the foreach loop.
This appears to also be related specifically to using a foreach loop. When I switched my code to a for loop and declare a local variable inside that loop to assign my string to, it worked correctly in VS2010.