5 ms·
Yes, they are now creating a new variable in the `foreach` loop each time. They aren't doing the same for regular `for` loops so their behavior with respect to
by noblethrasher 15y ago
Yes, they are now creating a new variable in the `foreach` loop each time.
They aren't doing the same for regular `for` loops so their behavior with respect to lambdas won't change.
- TheNinjaneer 15y agoTo add to this, Eric Lippert, a principal dev on the C# compiler team, mentions this in a StackOverflow response (http://stackoverflow.com/a/8899347/59111 http://stackoverflow.com/a/8899347/59111). He also blogged about the issue in general in a two part series, the first of which can be read here: Closing over the loop variable considered harmful (http://blogs.msdn.com/b/ericlippert/archive/2009/11/12/closing-over-the-loop-variable-considered-harmful.aspx http://blogs.msdn.com/b/ericlippert/archive/2009/11/12/closi...).