Why should events in C# take (sender, EventArgs)?

前端 未结 10 1266
轻奢々
轻奢々 2020-12-08 18:46

It\'s known that you should declare events that take as parameters (object sender, EventArgs args). Why?

10条回答
  •  萌比男神i
    2020-12-08 19:42

    Actually this is debatable whether or not this is the best practice way to do events. There is the school of thought that as events are intended to decouple two segments of code, the fact that the event handler gets the sender, and has to know what type to cast the sender into in order to do anything with it is an anti-pattern.

提交回复
热议问题