Double recursive extension : Func « LINQ « C# / CSharp Tutorial






using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

    static class DoubleApplicationExtensions
    {
        public static Func<T, T> ApplyTwice<T>(this Func<T, T> original)
        {
            return x => original(original(x));
        }
    }

    class MainClass
    {
        static void Main()
        {
            Func<int, int> incrementer = x => x + x;
            Func<int, int> doubleIncrementer = incrementer.ApplyTwice();

            Console.WriteLine(doubleIncrementer(5));
        }
    }








22.45.Func
22.45.1.Double recursive extension
22.45.2.Accumulator function
22.45.3.Add extension to Func
22.45.4.Build the necessary Func<> delegates using anonymous methods
22.45.5.Overloading By Delegate Return Type
22.45.6.Pass the delegates into the methods of Sequence
22.45.7.Lambda Expression for Func
22.45.8.Lambda Expression to retrieve string length