Removing event handlers

前端 未结 2 740
执念已碎
执念已碎 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

提交回复
热议问题