lambda表達式的出現基本上取代了delegate操做符的使用this
public MainWindow() { InitializeComponent(); this.button1.Click += button1_Click; } void button1_Click(object sender, RoutedEventArgs e) { this.textbox1.Text = "hello world"; }
使用delegate轉變爲匿名方法spa
public MainWindow() { InitializeComponent(); this.button1.Click += delegate(object sender, RoutedEventArgs e) { this.textbox1.Text = "hello world"; }; }
使用lambda表達式轉變爲code
public MainWindow() { InitializeComponent(); this.button1.Click += ( sender, e)=> { this.textbox1.Text = "hello world"; }; }