Is there an “anonymous” generic tag in C#, like '?' in Java?

前端 未结 6 1380
醉梦人生
醉梦人生 2020-12-09 08:05

In Java, one can declare a variable parameterised by an \"unknown\" generic type, which looks like this:

Foo x;

Is there an equiva

6条回答
  •  慢半拍i
    慢半拍i (楼主)
    2020-12-09 08:30

    AFAIK you can not do that in C#. What the BCL does and there are plenties of examples there is to create a class that is not generic and then create a generic class that inherits the base behavior from the previous one. See example below.

    class Foo
    {
    }
    
    class Foo : Foo
    {
    }
    

    The you can write something like this:

    Foo t = new Foo();
    

提交回复
热议问题