C# 如何声明返回相同类型Func委托的Func委托?

C# 如何声明返回相同类型Func委托的Func委托?,c#,delegates,func,C#,Delegates,Func,我想写一个方法,它做一些工作,并最终返回另一个与原始方法具有相同签名的方法。其思想是根据前面的字节值顺序处理字节流,而不进行递归。这样称呼它: MyDelegate executeMethod = handleFirstByte //What form should be MyDelegate? foreach (Byte myByte in Bytes) { executeMethod = executeMethod(myByte); //does stuff on byte and

我想写一个方法,它做一些工作,并最终返回另一个与原始方法具有相同签名的方法。其思想是根据前面的字节值顺序处理字节流,而不进行递归。这样称呼它:

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委托。但我遇到了一个问题,这导致了一个无终止的递归声明

Func<byte, Func<byte, <Func<byte, etc... >>>

Func当预定义的
Func
委托不足时,您可以简单地声明委托类型:

public delegate RecursiveFunc RecursiveFunc(byte input);
如果需要,也可以使用泛型:

public delegate RecursiveFunc<T> RecursiveFunc<T>(T input);
public委托RecursiveFunc RecursiveFunc(T输入);

不过,在编译时不知道该方法的签名。他不知道参数是
字节
@Servy,在这种情况下
delegate RecursiveFunc RecursiveFunc(T输入)
excellent-效果很好。在我的例子中,我知道它将是一个字节,但对于一般版本,它将是+1。