How do you provide a default type for generics?

后端 未结 6 1426
醉梦人生
醉梦人生 2020-12-30 18:58

I have a class that currently has several methods that take integer parameters. These integers map to operations that the application can perform. I\'d like to make the clas

6条回答
  •  隐瞒了意图╮
    2020-12-30 20:02

    So... why not use simple inheritance? Like:

    class MyGenericClass
    {
    }
    
    class MyGenericClass : MyGenericClass
    {
    }
    

    This way you can write both ways:

    var X = new MyGenericClass();
    var Y = new MyGenericClass(); // Is now MyGenericClass
    

提交回复
热议问题