Different behaviors with a for loop and a foreach loop with closures

后端 未结 3 1287
醉酒成梦
醉酒成梦 2020-12-11 12:31

I can\'t explain an issue I\'ve run across. Basically I get a different answer if I use lambda syntax in a foreach loop than if I use it in a for loop. In the code below I r

3条回答
  •  孤城傲影
    2020-12-11 13:00

    This is the infamous "closing over the loop variable" gotcha.

    • Closing over the loop variable considered harmful (and part two)

提交回复
热议问题