What are the implications of doing this...
this.myButton.Click += new EventHandler(this.myButton_Clicked);
...versus this?
this.myButton.Click += this.myButton_Clicked;
I suspect that the compiler is creating a new instance for me in the second example. I'm sure this is a bit of a newbie question, but Google didn't turn up anything. Can anyone give me some insight?
Benefits of DelegatingGives you the time and ability to focus on higher-level tasks. Gives others the ability to learn and develop new skills. Develops trust between workers and improves communication. Improves efficiency, productivity, and time management.
A delegate is a type-safe function pointer that can reference a method that has the same signature as that of the delegate. You can take advantage of delegates in C# to implement events and call-back methods. A multicast delegate is one that can point to one or more methods that have identical signatures.
Use the new keyword to instantiate a delegate. When creating a delegate, the argument passed to the new expression is written similar to a method call, but without the arguments to the method.
The 2nd syntax is a shortcut for the 1st one introduced in C# 2.0.
http://www.developer.com/net/csharp/article.php/3103031/Working-with-Delegates-Made-Easier-with-C-20.htm
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