39

Is this:

Button.Click -= new EventHandler(Button_Click);

the same as this:

Button.Click -= Button_Click;

I ask because to me it seems that the former is removing a new reference to a method, and the latter one is removing a method itself. But then again, maybe the new EventHandler part is implicit in the += or -= overload in case the programmer doesn't explicitly assign it like that?

In case it is different how about

Button.Click -= new EventHandler(Button_Click);

VS

Button.Click -= Button_Click;

Thanks.

Carlo
  • 25,602
  • 32
  • 128
  • 176

2 Answers2

47

It is the same. The second is merely syntactic sugar for the first, and equality comparison is overloaded appropriately for delegate types:

Two delegates of the same type with the same targets, methods, and invocation lists are considered equal.

Source: MSDN, Delegate.Equality Operator

Konrad Rudolph
  • 530,221
  • 131
  • 937
  • 1,214
0

The end result is the same. The compiler is inferring the type of delegate automatically and as a result the new operator is not required to create it.

Brian Gideon
  • 47,849
  • 13
  • 107
  • 150