That is all I know for handling the event. Any other syntax is just a scope game.
// one Button.Click += delegate { /* do something */ }; // two Button.Click += delegate(object s, EventArgs e) { /* do something */ }; // three RoutedEventHandler handler = (s, e) => { /* do something */ }; Button.Click += handler; Button.Click -= handler; // four Button.Click += (s, e) => { /* do something */ };
I understand that the numbers one / two are basically the same, with the exception of explicit arguments that can be used in the resulting logic. I also understand that the number three allows me to add a handler and remove it, which can be very important. And, I understand, the number four is a simplified version of the second number.
My question is more practical. Between these two syntaxes, are there any reasons to use one above the other, or are they basically two ways to do the same thing? And how do you know?
// two Button.Click += delegate(object s, EventArgs e) { /* do something */ }; // four Button.Click += (s, e) => { /* do something */ };
source share