lambda表达式的出现基本上取代了delegate操作符的使用
public MainWindow() { InitializeComponent(); this.button1.Click += button1_Click; } void button1_Click(object sender, RoutedEventArgs e) { this.textbox1.Text = "hello world"; }
使用delegate转变为匿名方法
public MainWindow() { InitializeComponent(); this.button1.Click += delegate(object sender, RoutedEventArgs e) { this.textbox1.Text = "hello world"; }; }
使用lambda表达式转变为
public MainWindow() { InitializeComponent(); this.button1.Click += ( sender, e)=> { this.textbox1.Text = "hello world"; }; }