Part 98 Anonymous methods in c#
2015-09-12 02:53
615 查看
What is an anonymous method?
Anonymous method is a method without a name. Introduced in C# 2.0,they provide us a way of creating delegate instances without having to write a separate method.
View Code
Anonymous method is a method without a name. Introduced in C# 2.0,they provide us a way of creating delegate instances without having to write a separate method.
public partial class Form1 : Form { public Form1() { InitializeComponent(); } private void Form1_Load(object sender, EventArgs e) { Button button = new Button(); button.Text = "click me"; this.Controls.Add(button); //button.Click += button_Click; button.Click += delegate(object send, EventArgs ea) { MessageBox.Show("you click me by anonymous method"); }; } void button_Click(object sender, EventArgs e) { MessageBox.Show("you just click me"); throw new NotImplementedException(); } }
View Code
相关文章推荐
- C#陷阱之构造函数调用虚方法
- CSharpGL(5)解析3DS文件并用CSharpGL渲染
- C#使用System.xml.linq来生成XML文件
- Part 86 to 88 Talking about Multithreading in C#
- C# winform 窗体从右下角向上弹出窗口效果
- 【转】c#实现字符串倒序的n种写法
- 怎么利用C#中的 webclient 创建cookie
- c# 高效读写文件
- C#中WebBrowser控件的使用
- C#学习笔记
- win2d绘制图片
- C#圆角窗体简单实现方法
- C#高级------XML
- WPF -- 关于XAML语言解析处理及XAML引用
- C# 实现MD5 Hash 计算
- C#高级泛型集合中的where
- 【C#】解决进行反序列化时出错:。InnerException 消息是“反序列化对象 属于类型 System.String 时出现错误。读取 XML 数据时,超出最大字符串内容长度配额 (8192)。
- Clr Via C#读书笔记----基元线程同步构造
- C# 实现抓取网页内容(一)
- C# Socket的安全关闭