Closing over the loop variable, part two

(This is part two of a two-part series on the loop-variable-closure problem. Part one is here.) UPDATE: We are taking the breaking change. In C# 5, the loop variable of a foreach will be logically inside the loop, and therefore closures will close over a fresh copy of the variable each time. The “for” loop…


Closing over the loop variable considered harmful

(This is part one of a two-part series on the loop-variable-closure problem. Part two is here.) UPDATE: We are taking the breaking change. In C# 5, the loop variable of a foreach will be logically inside the loop, and therefore closures will close over a fresh copy of the variable each time. The “for” loop…