Why don't all of these variables get treated the same way?

前端 未结 2 599
我寻月下人不归
我寻月下人不归 2021-02-15 00:26

I was checking that the position of variable declarations in VB.NET don\'t matter, except for scope, (for this question) and I thought I better check what happens when they\'re

2条回答
  •  清歌不尽
    2021-02-15 01:29

    From MSDN (emphasis mine) :

    [...]what the compiler basically does, when it enters a new scope containing a lifted variable, the compiler will check to see if an instance of closure already exists; if so, the compiler will create a new instance of closure and reset the value of the variable from the previous closure.

    Note that the compiler only does the above check if it detects a loop or a GoTo in the function where the closure is generated.

    Link

提交回复
热议问题