为什么要使用lambda表达式的Compile()?它表现更好吗?

时间:2019-02-28 16:01:01

标签: c# lambda

我了解结果以及如何执行编译后的表达式,但是为什么要这么做呢?

  // Lambda expression as data in the form of an expression tree.`
  System.Linq.Expressions.Expression<Func<int, bool>> expr = i => i < 5;
// Compile the expression tree into executable code.
Func<int, bool> deleg = expr.Compile();
// Invoke the method and print the output.
Console.WriteLine("deleg(4) = {0}", deleg(4));

/*  This code produces the following output:

   deleg(4) = True
*/

`

0 个答案:

没有答案