8

In C# is there any real difference (other than syntax) under the hood between:

myButton.Click += new EventHandler(myMemberMethod);

and

myButton.Click += myMemberMethod;

?

Alexander Kojevnikov
  • 17,580
  • 5
  • 49
  • 46
DuckMaestro
  • 15,232
  • 11
  • 67
  • 85
  • possible duplicate of [C# Event handlers](http://stackoverflow.com/questions/26877/c-sharp-event-handlers) – nawfal Jul 06 '14 at 20:38

2 Answers2

14

The second method is a shortcut to the first one, it was introduced in C# 2.0

See also this thread.

Community
  • 1
  • 1
Alexander Kojevnikov
  • 17,580
  • 5
  • 49
  • 46
5

They are exactly the same, its called syntax sugar.

There are a lot of things that arent needed, to get a better idea of them while programming you should try something like Resharper. It will color the unnecessary code in Grey. Not to mention a whole myriad of incredible tools and refactorings.

Dested
  • 6,294
  • 12
  • 51
  • 73