0

我目前正在将 XML 反序列化为函数 processText() 中的对象“X”。我想将一个函数作为参数传递,这样我就可以调用 processText 并将任意规则应用于对象 X。这似乎是使用委托的情况,但我不知道如何利用在线示例...

展示我尝试过的示例:

AiringProcessing ap = new AiringProcessing(localFiles[1]);
//  getZeroLengthAirings is the particular process I want to run during my text processing
AiringDelegate del = new AiringDelegate(ap.getZeroLengthAirings);
ap.processBatch(del);
4

1 回答 1

1

要将委托作为参数传递,您需要使用Action<T>()Func<T>取决于返回值(操作返回 void)。

这是一个使用动作的例子:

public void TakeADelegate(Action<string> action, string str)
{
  action(str);
}

与代表一起调用它:

this.TakeADelegate((string s) => { ... do work here ...})
于 2013-03-20T00:11:38.217 回答