Add extension to Func : Func « LINQ « C# / CSharp Tutorial






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

    static class CurryingExtensions
    {
        public static Func<A, Func<B, R>> myExt<A, B, R>(this Func<A, B, R> f)
        {
            return a => b => f(a, b);
        }
    }
    class MainClass
    {
        static void Main()
        {
            Func<int, int, int> adder = (x, y) => (x + y);
            Func<int, Func<int, int>> c = adder.myExt();

            Func<int, int> addsTwo = c(2);
            Console.WriteLine(addsTwo(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