c# Lambda

分配给委托类型
Func square = x => x * x; 
Console.WriteLine(square(25));
作为方法参数传递
ShowValue(x => x * x);  
private static void ShowValue(Func op){
Console.WriteLine("{0} x {0} = {1}",5,  op(5));
}
没有输入参数
Action line = () => Console.WriteLine();
多个参数和返回值(最后一个),多个语句(一般不超过3个)要使用{}
Func 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);

你可能感兴趣的:(C#)