所以我知道该怎么做:
void PrintFoo () { Console.Write("Foo");}
void DoSomething (Action methodToCall) { methodToCall();}
void Main () { DoSomething(PrintFoo); }
我想做什么:
void PrintFoo (string fooToPrint) { Console.Write(fooToPrint);}
void DoSomething (Action methodToCall) { methodToCall();}
void Main () { DoSomething(PrintFoo("Foo bar baz")); }
基本上调用带参数的动作
答案 0 :(得分:4)
使用lambda表达式:
{jetty.home} $ java -cp lib/jetty-util-9.3.6.v20151106.jar org.eclipse.jetty.util.security.Password "MyInterestingAndAwesomePassword"
答案 1 :(得分:0)
您还可以定义要求回调的参数类型的操作。
public void DoSomething(Action<string> Callback){
var result = getMyString();
Callback(result);
}
public void DoSomething(Action<string> CallBack, List<string> Parms){
var sb = new StringBuilder();
Parms.ForEach(p=> sb.Append(Parse(p));
Callback(sb.ToString());
}