我正在寻找一种方法来允许另一个类通过调用该类的方法向我的 Action 委托添加方法,而不是在第一个类上调用 Action。
这就是我需要的:
class Program
{
static void Main(string[] args)
{
Action Execute = delegate { };
ProgramTest prog = new ProgramTest(ref Execute);
prog.AddMethod();
Execute();
}
}
class ProgramTest
{
public Action execute;
public ProgramTest(ref Action action)
{
execute = action;
}
public void AddMethod()
{
execute += Print;
}
public void Print()
{
Console.WriteLine("test");
Console.ReadLine();
}
}
但是,当我调用 Execute() 时,什么也没有发生。
我怎样才能让它工作?
慕容3067478
精慕HU
慕标5832272
qq_花开花谢_0
相关分类