Local variables with Delegates

前端 未结 3 1551
逝去的感伤
逝去的感伤 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:35

    You need to capture the value of the variable within the closure/delegate, else it can be modified, like you saw.

    Assign currentValue to a variable local (inside) to the delegate.

提交回复
热议问题