How do I create a new delegate type based on an existing one, in C#?

前端 未结 4 1087
别那么骄傲
别那么骄傲 2021-02-12 21:23

Is there any way that I can create a new delegate type based on an existing one? In my case, I\'d like to create a delegate MyMouseEventDelegate which would have th

4条回答
  •  长发绾君心
    2021-02-12 22:16

    I you only want to achieve compile time type checking I guess it would be enough to create specialized EventArgs classes for the cases that you describe. That way you can still take advantage of the pre-defined delegates:

    class RightMouseButtonEventArgs : MouseEventArgs {}
    class LeftMouseButtonEventArgs : MouseEventArgs {}
    
    EventHandler
    EventHandler
    

提交回复
热议问题