How wrong is it to create an event handler delegate with out the standard (Obj sender, EventArgs args) signature?

前端 未结 3 524
野趣味
野趣味 2021-02-05 19:18

I understand the benefits of using the standard MS event handler delegate signature as it allows you to easily expand on the information passed through the event with out breaki

3条回答
  •  陌清茗
    陌清茗 (楼主)
    2021-02-05 20:05

    In practice how often do people [not use EventArgs derived classes].

    I have never encountered a time when EventArgs derived classes have not been used. As you say yourself, it increases your ability to change your code later. I would also argue that the readability is improved, since it's easy to see that this is an event handler.

    Is it worth it to create a separate NameChangedEventArgs class, or for simple events like this is it acceptable to just return the arguments directly through the delegate arguments?

    You seem to say that you would use EventArgs for event handlers with more params and not use it for instances like this. Honestly, that is simply not an option when programming in C#. Consistency is a must, especially in today's world of forum's like this, open source projects, etc where it's easy to lose it. Sure if you are programming this under a rock, you may do whatever you like, but the greater C# community will thank you for following standards and especially using consistency in you code.

提交回复
热议问题