Skip to main content
 首页 » 编程设计

c#之如何将变量定义为方法

2024年02月23日16yxwkf

一个例子:

class SpecialButton 
{ 
   public SpecialButton(ButtonConfig conf, Method definedMethod) 
   { 
       button = new Button(); 
       button.Location = conf.Location; 
       //etc. 
       button.Click += new System.EventHandler(definedMethod); 
   } 
} 

是否可以将变量定义为方法?我想对来自此类外部的此点击事件使用委托(delegate)。

谢谢。

请您参考如下方法:

我会使用 Action<Object, EventArgs>或者只是 EventHandler .