Search Results

Search found 1 results on 1 pages for 'captaincasey'.

Page 1/1 | 1 

  • C# Generic method type argument inference

    - by CaptainCasey
    Is there any way that I can generalise the type definitions here? Ideally, I'd like to be able to change the type of 'testInput' and have test correctly infer the type at compile time. public static void Run() { var testInput = 3; var test = ((Func<int, int>) Identity).Compose<int,int,int>(n => n)(testInput); Console.WriteLine(test); } public static Func<T, V> Compose<T, U, V>(this Func<U, V> f, Func<T, U> g) { return x => f(g(x)); } public static T Identity<T> (this T value) { return value; }

    Read the article

1