1.Expression
>是表达式
//使用LambdaExpression构建表达式树 Expression
int,
int,
int,
int>> expr = (x, y, z) => (x + y) / z; Console.WriteLine(expr.Compile()(
1,
2,
3));
2.Func
委托 封装一个具有一个参数并返回 TResult 参数指定的类型值的方法。 public delegate TResult Func
(T arg) 类型参数 in T 此委托封装的方法的参数类型 out TResult 此委托封装的方法的返回值类型。 arg 类型:T 此委托封装的方法的参数。 返回值 类型:TResult 此委托封装的方法的返回值。
string mid = ",middle part,"; ///匿名写法 Func<string, string> anonDel = delegate(string param) { param += mid; param += " And this was added to the string."; return param; }; ///λ表达式写法 Func<string, string> lambda = param => { param += mid; param += " And this was added to the string."; return param; }; ///λ表达式写法(整形) Func<int, int> lambdaint = paramint => { paramint = 5; return paramint; }; ///λ表达式带有两个参数的写法 Func<int, int, int> twoParams = (x, y) => { return x*y; }; MessageBox.Show("匿名方法:"+anonDel("Start of string")); MessageBox.Show("λ表达式写法:" + lambda("Lambda expression")); MessageBox.Show("λ表达式写法(整形):" + lambdaint(4).ToString()); MessageBox.Show("λ表达式带有两个参数:" + twoParams(10, 20).ToString());
参考来源: http://www.cnblogs.com/xcsn/p/4520081.html
发布者:全栈程序员-站长,转载请注明出处:https://javaforall.net/229086.html原文链接:https://javaforall.net
