Problem with delegates in C#

后端 未结 4 1069
慢半拍i
慢半拍i 2021-02-06 08:29

In the following program, DummyMethod always print 5. But if we use the commented code instead, we get different values (i.e. 1, 2, 3, 4). Can anybody please explain why this is

4条回答
  •  星月不相逢
    2021-02-06 09:21

    I think it is because the variable i is put to the heap (it's a captured variable)

    Take a look at this answer.

提交回复
热议问题