Local variables with Delegates

前端 未结 3 1549
逝去的感伤
逝去的感伤 2020-12-09 09:06

This is clearly not appears like it wouldn\'t be a best practice. Can someone explain why it would not be a best practice or how this works? Any books or ar

3条回答
  •  抹茶落季
    2020-12-09 09:51

    I suppose more the question I am asking is that how is it working with a local variable [MG edit: "Ack - ignore this..." was added afterwards]

    That is the point; it really isn't a local variable any more - at least, not in terms of how we normally think of them (on the stack etc). It looks like one, but it isn't.

    And for info, re "not good practice" - anonymous methods and captured variables are actually an incredibly powerful tool, especially when working with events. Feel free to use them, but if you are going down this route, I would recommend picking up Jon's book to make sure you understand what is actually happening.

提交回复
热议问题