分配给委托类型
Func<int, int> square = x => x * x;
Console.WriteLine(square(25));
作为方法参数传递
ShowValue(x => x * x);
private static void ShowValue(Func<int,int> op){
Console.WriteLine("{0} x {0} = {1}",5, op(5));
}
没有输入参数
Action line = () => Console.WriteLine();
多个参数和返回值(最后一个),多个语句(一般不超过3个)要使用{}
Func<int,int,bool> testEquality = (x, y) => x == y;
使用元组
var numbers = (2, 3, 4, 5, 6);
Func<(int, int, int, int, int), (int, int, int, int, int)> doubleThem = (n) => (n.Item1 * 2, n.Item2 * 2, n.Item3 * 2, n.Item4 * 2, n.Item5 * 2);
var doubledNumbers = doubleThem(numbers);
Func<int, int> square = x => x * x;
Console.WriteLine(square(25));
作为方法参数传递
ShowValue(x => x * x);
private static void ShowValue(Func<int,int> op){
Console.WriteLine("{0} x {0} = {1}",5, op(5));
}
没有输入参数
Action line = () => Console.WriteLine();
多个参数和返回值(最后一个),多个语句(一般不超过3个)要使用{}
Func<int,int,bool> testEquality = (x, y) => x == y;
使用元组
var numbers = (2, 3, 4, 5, 6);
Func<(int, int, int, int, int), (int, int, int, int, int)> doubleThem = (n) => (n.Item1 * 2, n.Item2 * 2, n.Item3 * 2, n.Item4 * 2, n.Item5 * 2);
var doubledNumbers = doubleThem(numbers);