我想编写一个方法来完成一些工作并最终返回另一个与原始方法具有相同签名的方法。这个想法是根据前一个字节值顺序处理字节流,而不用递归。通过这样调用它:
MyDelegate executeMethod = handleFirstByte //What form should be MyDelegate?
foreach (Byte myByte in Bytes)
{
executeMethod = executeMethod(myByte); //does stuff on byte and returns the method to handle the following byte
}
为了移交方法,我想将它们分配给 Func 委托(delegate)。但是我遇到了一个问题,这导致递归声明没有终止......
Func<byte, Func<byte, <Func<byte, etc... >>>
我在这里迷路了。我该如何解决这个问题?
最佳答案
您可以在预定义的 Func<...>
时简单地声明一个委托(delegate)类型委托(delegate)不够:
public delegate RecursiveFunc RecursiveFunc(byte input);
如果你需要它,你也可以使用泛型:
public delegate RecursiveFunc<T> RecursiveFunc<T>(T input);
关于c# - 如何声明返回相同类型的 Func Delegate 的 Func Delegate?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27989296/