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

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

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

10条回答
  •  野趣味
    野趣味 (楼主)
    2020-12-08 19:29

    This allows the consuming developer the ability to write a single event handler for multiple events, regardless of sender or event.

    Edit: Why would you need a different pattern? You can inherit EventArgs to provide any amount of data, and changing the pattern is only going to serve to confuse and frustrate any developer that is forced to consume this new pattern.

提交回复
热议问题