简体   繁体   English

为什么在C#中我们需要对象发送者作为参数事件处理程序?

[英]Why do we need the object sender as a parameter eventhandler in c#?

I would like to know why we need the object sender as a parameter while we can pass it using the eventargs object like below: 我想知道为什么我们需要使用对象发送者作为参数,同时我们可以使用eventargs对象传递它,如下所示:

SpecialEvent(this,new SpecialEventArgs(..));
void Func(object _sender,SpecialEventArgs _e){}

SpecialEvent(new SpecialEventArgs(this,..));
void Func(SpecialEventArgs _e){}

Thx 谢谢

What if you bind that event handler to multiple buttons? 如果将该事件处理程序绑定到多个按钮怎么办? It would be nice to see which button invoked the handler. 很高兴看到哪个按钮调用了处理程序。 There is no value in moving this reference into the event args. 将此引用移到事件args中没有任何价值。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM