我定义了两个类:
public class ControllerEx
{
public delegate void stopMachineDelegate();
public stopMachineDelegate stopMachin; public void Add(stopMachineDelegate stopMethod)
{
this.stopMachin += stopMethod;
} public void Remove(stopMachineDelegate stopMethod)
{
this.stopMachin -= stopMethod;
} public void ShutDown()
{
this.stopMachin();
} }------------------------------------------------------------------------
public class Folder
{
public void StopFolding()
{
Console.WriteLine("Folder Closed");
} }
------------------------------------------------------------------------
我是这样调用的:
Folder folder = new Folder();ControllerEx obj = new ControllerEx();obj.Add(folder.StopFolding);提示错误:
在不带括号的情况下引用了方法“ConsoleApplication._05.Folder.StopFolding()”
public class ControllerEx
{
public delegate void stopMachineDelegate();
public stopMachineDelegate stopMachin; public void Add(stopMachineDelegate stopMethod)
{
this.stopMachin += stopMethod;
} public void Remove(stopMachineDelegate stopMethod)
{
this.stopMachin -= stopMethod;
} public void ShutDown()
{
this.stopMachin();
} }------------------------------------------------------------------------
public class Folder
{
public void StopFolding()
{
Console.WriteLine("Folder Closed");
} }
------------------------------------------------------------------------
我是这样调用的:
Folder folder = new Folder();ControllerEx obj = new ControllerEx();obj.Add(folder.StopFolding);提示错误:
在不带括号的情况下引用了方法“ConsoleApplication._05.Folder.StopFolding()”
在以前版本可能需要这样写:
obj.Add(new ControllerEx.stopMachineDelegate(folder.StopFolding));