Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/317.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 重载方法以允许将其添加为事件处理程序?_C#_Events_Overloading - Fatal编程技术网

C# 重载方法以允许将其添加为事件处理程序?

C# 重载方法以允许将其添加为事件处理程序?,c#,events,overloading,C#,Events,Overloading,我正在重载一个方法,以便可以将其分配给事件。必须有更好的方法来做到这一点 myMethod(){ //Does some stuff... } myMethod(object sender, FormClosingEventArgs e){ myMethod(); } Form.FormClosing += new FormClosingEventHandler(myMethod); 匿名方法在这里很有效: form.FormClosing += delegate { myM

我正在重载一个方法,以便可以将其分配给事件。必须有更好的方法来做到这一点

myMethod(){
    //Does some stuff...
}
myMethod(object sender, FormClosingEventArgs e){
    myMethod();
}

Form.FormClosing += new FormClosingEventHandler(myMethod);

匿名方法在这里很有效:

form.FormClosing += delegate { myMethod(); };

编译器与您所做的差不多,但读取的管道代码更少。

@pst这有什么帮助?过载解决在这里不是问题