匿名方法的写法
button1.Click += delegate(object sender, EventArgs e)
{
MessageBox.Show("hello");
};
精简之后
button1.Click += delegate
{
MessageBox.Show("hello");
};
C#3.0中引入Lambda表达式
button1.Click += (x, y) => MessageBox.Show("hello");
带返回值的Lambda表达式
// public delegate bool Predicate<in T>(T obj); // Predicate的定义
Predicate<int> pre = x => x == 3;
Predicate<int> pre2 = x =>{ return x == 3; };