C# - Create an EventHandler that can take any number of parameters

后端 未结 3 1365
孤街浪徒
孤街浪徒 2021-02-08 03:07

I wish to create a custom EventHandler that can have any number of objects as its parameters and the objects it gets isn\'t known in advance.

I know I can pass it an Obj

3条回答
  •  借酒劲吻你
    2021-02-08 03:43

    There's nothing to stop you declaring a delegate that accepts a params array, the same as you would define any other method which takes multiple arguments:

    delegate void someCustomEvent(params object[] args);
    
    event someCustomEvent sce;
    

    However, it would be unusual. As Kent says, it's more normal to follow the convention on the .Net platform of having event handlers accepting two arguments, the sender (object), and the event arguments (EventArgs, or something deriving from it).

提交回复
热议问题