且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何创建基于现有一个新的委托类型,在C#中?

更新时间:2023-11-30 13:42:16

嗯,这是因为复制从原来的委托声明一样简单。没有什么在C#中自动执行此操作的,但我不能看到它的太大负担:

Well, it's as simple as copying the delegate declaration from the original. There's nothing in C# to do this automatically, but I can't see it's much of a burden:

public delegate void MyLeftClickHandler(object sender, MouseEventArgs e);
public delegate void MyRightClickHandler(object sender, MouseEventArgs e);



这不像 MouseEventHandler 将改变任何时间很快...

It's not like MouseEventHandler is going to change any time soon...

你有没有真正被因在错误的地方使用了错误的代表,虽然虫子咬伤?我不记得曾经有发现这个问题我自己,在我看来,你是引入更多的工作(和其他开发人员不熟悉的一套代表) - ?你肯定是值得的。

Have you actually been bitten by bugs due to using the wrong delegates in the wrong places though? I can't remember ever having found this a problem myself, and it seems to me you're introducing more work (and an unfamiliar set of delegates for other developers) - are you sure it's worth it?