Both of the following variations compile and on the surface seem to behave in the same way. Aside from syntax sugar are there any other differences?
someObject.SomeEvent += new SomeEventHandler(someObject_SomeEvent);
someObject.SomeEvent += someObject_SomeEvent;
The two are exactly the same. If you use the second (shorter) form, the compiler just puts in the delegate type for you.
There is no reason to use the syntax which explicitly constructs the delegate, unless you wish the delegate type to exist within the code (for readability, etc).
The new, shorter version of creating a delegate has been introduced with the vs2003 compiler as far as I remember. It is just a syntactic sugar over the longer version.
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