Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Do c# lambdas exist only at compile time? [duplicate]

Tags:

c#

lambda

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?

like image 313
Fayilt Avatar asked Aug 05 '13 12:08

Fayilt


1 Answers

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.

like image 72
usr Avatar answered Oct 26 '22 22:10

usr