1.Expression<Func<T,TResult>>是表达式
Expression<Func<int, int, int, int>> expr = (x, y, z) => (x + y) / z;
Console.WriteLine(expr.Compile()(1, 2, 3));
2.Func<T, TResult> 委托
封装一个具有一个参数并返回 TResult 参数指定的类型值的方法。
public delegate TResult Func<in T, out TResult>(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