lambda表达式怎么取得返回的值?

如下

Expression<Fun<myentity,int>> zz=GetLambda();

如何取得其中函数返回的int值?


隔江千里
浏览 507回答 1
1回答

POPMUISE

using System;using System.Linq.Expressions;namespace ConsoleApplication1{ &nbsp; &nbsp;class Program &nbsp; &nbsp;{ &nbsp; &nbsp; &nbsp; &nbsp;static void Main(string[] args) &nbsp; &nbsp; &nbsp; &nbsp;{ &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;//表达式创建 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;Expression<Func<int, int>> zz = m => m + 1; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;//将表达式编译 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;Func<int, int> foo = zz.Compile(); &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;//获取返回结果 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;int result = foo(9); &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;Console.WriteLine(result.ToString()); //output: 10 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;Console.ReadKey(); &nbsp; &nbsp; &nbsp; &nbsp;} &nbsp; &nbsp;}}
打开App,查看更多内容
随时随地看视频慕课网APP