Removing event handlers

前端 未结 2 724
执念已碎
执念已碎 2020-11-28 12:00

Is this:

Button.Click -= new EventHandler(Button_Click);

the same as this:

Button.Click -= Button_Click;

相关标签:
2条回答
  • 2020-11-28 12:09

    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

    0 讨论(0)
  • 2020-11-28 12:10

    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.

    0 讨论(0)
提交回复
热议问题