Why doesn't C# do “simple” type inference on generics?

后端 未结 6 1264
谎友^
谎友^ 2021-01-03 05:45

Just curious: sure, we all know that the general case of type inference for generics is undecidable. And so C# won\'t do any kind of sub-typing at all: if Foo

6条回答
  •  走了就别回头了
    2021-01-03 06:25

    Since instances of generic classes have different method signatures I don't belive it would make any sence to consider specific classes to be inherited from base classes.

    class Base 
    {
     public T Method() { return default(T);}
    }
    

    If you suggest that Base and Base than both of them have "Method" with the same signature (coming from base class) and it can be called by using reference to base class. Can you please explain what obvious return value "Method" will have in your system if one points to Base or Base object by pointing to base class?

提交回复
热议问题