【发布时间】:2011-04-30 06:00:08
【问题描述】:
我希望能够将方法作为参数传递。
例如..
//really dodgy code
public void PassMeAMethod(string text, Method method)
{
DoSomething(text);
// call the method
//method1();
Foo();
}
public void methodA()
{
//Do stuff
}
public void methodB()
{
//Do stuff
}
public void Test()
{
PassMeAMethod("calling methodA", methodA)
PassMeAMethod("calling methodB", methodB)
}
我该怎么做?
【问题讨论】:
-
你应该可以和代表一起做。
-
您运行的是哪个版本的 .NET 框架?
-
3.5,有人可以用上面的例子告诉我吗?谢谢
-
这能回答你的问题吗? Pass Method as Parameter using C#