16

Am I right in saying that lambda expressions exist only at compile time, and once compiled they become either an Expression (LambdaExpression?) or a delegate?

Fayilt
  • 1,042
  • 7
  • 16

1 Answers1

16

Yes. In addition to a delegate, lambdas become a generated method. The delegate refers to that method. If they close over variables, the method becomes an instance method on a generated class holding the closure state.

In that sense you can use a lambda and local variables to create a class with fields and one method, similar to JavaScript.

Mike Christensen
  • 82,887
  • 49
  • 201
  • 310
usr
  • 165,323
  • 34
  • 234
  • 359