I have classes that inherit from an abstract base class, and I want to pass a List
of any of those classes into a method that that has a List
of the base class as a parameter. How can I make that happen?
Here is want I've tried -
public abstract class MyBaseClass {}
public class MyClass1 : MyBaseClass {}
//Inside another class
public void MyMethod(List<MyBaseClass> listOfBaseClass){}
//Inside another class
List<MyClass1> myClass1List = new List<MyClass1>();
MyMethod(myClass1List); //ERROR HERE, This method call does not compile
Is there anyway to accomplish what I am trying to do?