Semantics of Captured Variables
Can someone please explain the semantics of captured variables in the following two cases:
(1) an anonymous method (a lambda expression) that captures only instance and static (class) fields (but not local variables or parameters), and
(2) an anonymous method that captures local variables and parameters, and possibly instance and static fields.
Also, what is the relationship between closures and captured variables?
A closure is an object (usually) that contains all captured variables used by a lambda.
If the lambda uses instance fields, it's actually implicitly capturing the this
instance, then accessing its members.
If it only uses static fields, it doesn't have a closure at all; static fields can be accessed without context.
链接地址: http://www.djcxy.com/p/51550.html上一篇: 重用lambda表达式
下一篇: 捕获变量的语义