Lambda的使用以及概念

匿名函数:没有名字的函数;

符号:=>  读作:goes to

//无参无返回值
action act1=()=>Console.WriteLine("无参无返回值");
act1.Invoke();
//有参无返回值
action <string> act2=x=>Console.WriteLine("有参无返回值");
act2.Invoke("李四");
//无参有返回值;
Func<int> func1=()=>{return 200;};
int num=func1.Invoke();
console.Writeline(num);
//有参有返回值;
Func<int,int,int> func2=(x,y)=>{return x+y};
int result=func2.Invoke(10,20);
console.writeline(result);
发布了14 篇原创文章 · 获赞 0 · 访问量 128

猜你喜欢

转载自blog.csdn.net/m0_46454966/article/details/105460052