I usually use interfaces or base classes as parameter types when passing derived objects to a method. for example
Method1(ICar car);
Method2(BaseClass derivedClass);
But what about a base base class when the descendant class is not common?
public class GenericBaseClass<T> where T : BaseClass
{}
public class GenericDerivedClass1 : GenericBaseClass<DerivedClass1>
{}
I can write something like
Method3(GenericBaseClass<BaseClass> class);
but I cannot pass an object of type to this method am GenericDerivedClass1.
Is there any way to pass my descendant class to this method?
source
share