使用Lambda表达式重构委托
生活随笔
收集整理的這篇文章主要介紹了
使用Lambda表达式重构委托
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
1.事件
通常寫法(C# 1.0)
this.button.Click +=new EventHandler(button_Click); void button_Click(object sender, EventArgs e) { throw new NotImplementedException(); }在C#2.0中使用匿名方法
this.button.Click +=delegate{ throw new NotImplementedException(); }; //或者 this.button.Click +=delegate(object obj, EventArgs args)throw new NotImplementedException(); };使用Lamba表達式
this.button.Click += (s, ev) => { throw new NotImplementedException(); };2.一般委托
?
Func<int,int,int> max=(a,b)=>{if (a > b)return a;return b;}; int rst=max(222,134);Console.Write(rst)參考自http://www.cnblogs.com/neozhu/archive/2010/07/16/1778864.html
轉載于:https://www.cnblogs.com/FlyCat/archive/2012/04/25/2579984.html
總結
以上是生活随笔為你收集整理的使用Lambda表达式重构委托的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: oracle学习之三--多表查询
- 下一篇: 来博客园第一天