Consider the following code:
abstract class SomeClassX<T> { // blah } class SomeClassY: SomeClassX<int> { // blah } class SomeClassZ: SomeClassX<long> { // blah }
I want a collection of SomeClassX<T>’s, however, this isn’t possible since SomeClassX<int> != SomeClassX<long> and List<SomeClassX<>> isn’t allowed.
So my solution is to have SomeClassX<T> implement an interface and define my collection as, where ISomeClassX is the interface:
class CollectionOfSomeClassX: List<ISomeClassX> { // blah }
Is this the best way to do this, or is there better way?
I would either use the interface you suggested, or make SomeClassX inherit from another class. It really depends on what you need to do with the objects in your collection. Whatever functionality they are going to have in common should go in a base class, or interface if that seems more appropriate.