您的位置:首页 > 编程语言 > C#

C#中的lambda表达式与委托的关系

2017-02-26 20:38 190 查看
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace LambdaSpace
{
public delegate void NoReturnNoPara();
class LambdaTest
{
public static void Show()
{
NoReturnNoPara method0 = new NoReturnNoPara(ShowSth);//.net1.1最原始的方法

NoReturnNoPara method1 = ShowSth;//简写的方法

NoReturnNoPara method2 = new NoReturnNoPara(
delegate()
{
Console.WriteLine("delegate show sth");
}
);//匿名方法的写法。很有用,有些回调函数可以

NoReturnNoPara method3 = new NoReturnNoPara(
()=>//箭头左边是参数,右边是方法体
{
Console.WriteLine("lambda show sth");
}
);//.net 3.0之后出现了lambda表达式

}

private static void ShowSth()
{
Console.WriteLine("show sth");
}
}
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: