Lambda拉姆达表达式

  拉姆达表达式常用于委托,也就是说拉姆达表达式是匿名函数,简单点就是函数。

 

 a => a.Equals("string"); 
//原形为:

(a) => { return a.Equals("string");}

//相当于equals函数:
public bool equals(string a)
{
return a.Equals("string");
}
可创建委托:(三者等效)
 Func<string, bool> del = a => a.Equals("string");
Func<string, bool> del = (a) => { return a.Equals("string");} Func<string, bool> del = equals;

例1:
 
 
Func<string, bool> del = equals;
//表示传入的参数为string类型,返回类型为bool,使用的时候如这样:
if(del("string"))
Console.WriteLine("this is a string"); //结果输出为:this is a string
 例2:
delegate int del(int i); static void Main(string[] args) { del myDelegate = x => x * x; int j = myDelegate(5); //j = 25  }  


 

转载于:https://www.cnblogs.com/weimingxin/p/8109804.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值