Why is C# unable to infer the generic type argument type from a non-generic static method's signature?

后端 未结 2 2251
予麋鹿
予麋鹿 2021-02-19 22:36

I have conducted the following inference tests:

static class InferenceTest {
    static void TakeInt(int a) { }
    static int GiveInt() { return 0; }
    static         


        
2条回答
  •  野的像风
    2021-02-19 23:07

    Method parameters are not inspected.

    As suggested, in ConsumeFunc1Func2 the compiler is inferring only from return values. In ConsumeFunc2c, TakeAndGiveInt signature is not inspected to see if its method parameter type is actually of the same type of the method return type cause... method parameters are not inspected!

提交回复
热议问题