C# event with custom arguments

前端 未结 7 1521
庸人自扰
庸人自扰 2020-12-05 09:29

I want to have an event that takes an enum only as the argument. For example

public enum MyEvents{
   Event1
}

// how do I declare this to take enum MyEvent         


        
7条回答
  •  借酒劲吻你
    2020-12-05 10:07

    You declare a delegate for the parameters:

    public enum MyEvents { Event1 }
    
    public delegate void MyEventHandler(MyEvents e);
    
    public static event MyEventHandler EventTriggered;
    

    Although all events in the framework takes a parameter that is or derives from EventArgs, you can use any parameters you like. However, people are likely to expect the pattern used in the framework, which might make your code harder to follow.

提交回复
热议问题