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

我想编写一个方法来做一些工作,最后返回另一个方法与原始方法相同的签名。 这个想法是依次处理一个字节流,而不是进入递归。 通过这样称呼它:

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>> 

我不知何故在这里迷路了。 我怎么能绕过那个?

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

 public delegate RecursiveFunc RecursiveFunc(byte input); 

如果您需要它,您也可以使用generics:

 public delegate RecursiveFunc RecursiveFunc(T input);