本文介绍了事件处理程序,新的或不新的的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

说我有一些对象(SomeObject),其EventHandler定义为

public event EventHandler MyObjectsEventHandler;


然后,我有另一个使用SomeObject的对象(ObjectUser),并且正在设置事件处理程序...我可以做两件事(我知道),但是我不确定性能是否有所不同,并且想要如果有人可以提供的说明.

AnotherObject具有方法:

Say I have some object (SomeObject) with an EventHandler defined as

public event EventHandler MyObjectsEventHandler;


Then I have another object (ObjectUser) that uses SomeObject and I am setting up the event handler... I can do 2 things (that I know of) but I am not sure if there is a difference in performance etc. and would like an explanation if someone can provide it.

AnotherObject has method:

void someObject_MyObjectsEventHandler(object sender, EventArgs e)
{
            //Does Stuff        
}




它们之间有什么区别?:




What is the difference between these?:

someObject.MyEventHandler += new EventHandler(someObject_MyObjectsEventHandler);





someObject.MyEventHandler += someObject_MyObjectsEventHandler

推荐答案


这篇关于事件处理程序,新的或不新的的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

11-03 10:39