Looks like you are confusing expressions:
Expression<Func<int, string>> myFuncExpr = someInt => someInt.ToString();
and delegates:
Func<int, string> myFunc = someInt => someInt.ToString();
They have the similar declaration syntax, when using lambdas, but the expression tree won't compile into delegate, until you call myFuncExpr.Compile()
. Every time you call Compile
, the compilation will take place, because expression tree is a way to represent a code (C# code in particular), not a code itself.
From the other hand, the delegate will be compiled once with the rest of source code from your assembly. From the point of compiler, lambda here is just another way to declare a method body, that is, the code itself. So, there's no any reason to compile it somehow differently.