C# Know how many EventHandlers are set?

后端 未结 3 632
生来不讨喜
生来不讨喜 2021-01-04 06:31

As we all know, we can create an EventHandler and add methods to it N number of times. Like:

   // Declare and EventHandler     
   public event EventHandler         


        
3条回答
  •  没有蜡笔的小新
    2021-01-04 07:23

    What you are describing is a field-like event. It is the same as the longhand event declaration, except no body.

    From inside the class, you can set the event to null. From outside the class you cannot do this. Events follow a subscribe and unsubscribe methodology. Within the class you reference the variable, outside the class you reference the event.

    See this answer by Jon Skeet on events.

提交回复
热议问题