Is there a difference here?
Button1.Click -= new EventHandler(Button1_Click);
and
Button1.Click -= Button1_Click;
The second method doesn't seem to work for me but I've seen it used when Google-ing 'how to remove an event handler'. Edit: Actually neither are working for me, even so should either work interchangeably?
Update:
The reason these didn't appear to work for me is because I had AutoPostBack=true on my controls. I wasn't setting breakpoints to see if the events were called, I just watched the browser to see if it refreshed (meaning a post-back).
Those two pieces of code are the same. The second syntax (called "method group conversion") was a new feature added in C# 2.0.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With