/// <Summary>
/// Factorial and Accumulation
/// Func <int, int> the first one is the delegate method parameter type, and the last one is the delegate return type.
/// </Summary>
Public class Factorial
{
/// <Summary>
/// Delegate the factorial method call
/// </Summary>
Public static Func <int, int> functirial = RFunc <int, int> (m, n) => n = 1? 1: n * m (n-1 ));
Public static Func <int, int> cumulative = RFunc <int, int> (m, n) => n = 0? 0: n + m (n-1 ));
/// <Summary>
/// A single parameter has a return value Recursive Method generator.
/// </Summary>
/// <Typeparam name = "T"> parameter type. </Typeparam>
/// <Typeparam name = "TResult"> return value type. </Typeparam>
/// <Param name = "f"> recursive operation implementation </param>
/// <Returns> </returns>
Public static Func <T, TResult> RFunc <T, TResult> (Func <T, TResult>, T, TResult> f)
{
Return x => f (RFunc (f), x );
}
}
External call
Factorial. functirial (4)
From liuyun 521