2

So I'm a newbie, i was trying few things out, and I can't understand why the type can't be infered from the Test method, but can be infered from lambda expression.

class Program
{
    public delegate T2 DelegateTest<T1, T2>(T1 t1, T2 t2);

    public static T2 GenericMethodPlusDelegate<T1, T2>(DelegateTest<T1, T2> del)
    {
        return default;
    }

    static void Main(string[] args)
    {
        GenericMethodPlusDelegate(Test); //type cannot be infered, won't compile
        GenericMethodPlusDelegate((int x, char y) => y); //compiles
    }

   public static char Test(int x, char y)
    {
        return y;
    }

}
Flick
  • 21
  • 1
  • 1
    Does this answer your question? [type argument from Action cannot be inferred, but from Func can be](https://stackoverflow.com/questions/22669968/type-argument-from-actiont-cannot-be-inferred-but-from-funct-can-be) – Sathish Guru V Sep 04 '20 at 11:20

0 Answers0