Kon*_*lph 56
您必须将lambda分配给其他类型:
// Gives you a delegate:
Func<int, int> f = x => x * 2;
// Gives you an expression tree:
Expression<Func<int, int>> g = x => x * 2;
方法参数也是如此.但是,一旦将这样的lambda表达式分配给Func<>类型,就无法返回表达式树.
只是为了扩展Konrad的答案,并纠正皮埃尔,你仍然可以从IL编译的lambda中生成一个Expression,尽管它并不是非常优雅.增加康拉德的例子:
// Gives you a lambda:
Func<int, int> f = x => x * 2;
// Gives you an expression tree:
Expression<Func<int, int>> g = x => f(x);
| 归档时间: | 
 | 
| 查看次数: | 20132 次 | 
| 最近记录: |