C# event with custom arguments

前端 未结 7 1518
庸人自扰
庸人自扰 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条回答
  •  Happy的楠姐
    2020-12-05 10:00

    Example with no parameters:

    delegate void NewEventHandler();
    public event NewEventHandler OnEventHappens;
    

    And from another class, you can subscribe to

    otherClass.OnEventHappens += ExecuteThisFunctionWhenEventHappens;
    

    And declare that function with no parameters.

提交回复
热议问题