Generics with Generic Parameters and Abstract class

前端 未结 4 414
不思量自难忘°
不思量自难忘° 2020-12-03 14:03

I\'ve got two generic base classes. The second generic class has a constraint on its parameter of the first class.

abstract class FirstClass {...}
         


        
4条回答
  •  囚心锁ツ
    2020-12-03 15:02

    In my experience it is easiest to create non-generic interface to generic classes. It also solves the problem when you need to cast to the base class without knowing the generic type.

    interface IFirstClass {...}
    
    abstract class FirstClass : IFirstClass {...}
    
    abstract class SecondClass where T : IFirstClass {...}
    

提交回复
热议问题