c# Lambda

分配给委托类型
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);
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值