How can I clear event subscriptions in C#?

前端 未结 10 1882
野趣味
野趣味 2020-11-30 18:43

Take the following C# class:

c1 {
 event EventHandler someEvent;
}

If there are a lot of subscriptions to c1\'s someEven

10条回答
  •  情深已故
    2020-11-30 19:15

    Add a method to c1 that will set 'someEvent' to null.

    public class c1
    {
        event EventHandler someEvent;
        public ResetSubscriptions() => someEvent = null;    
    }
    

提交回复
热议问题