(How) can I cast a derived class type in place of a base class? (I think it's cast I'm looking for - I think this is a simple thing to do but every answer I click on is wrapped in complexity)
E.g. if I have declared somewhere I want a list of BASECLASS
- can I not put in to this list any of its DERIVEDCLASSES
? It makes sense that I could, because they'll have all the same properties (but with some extras)
class baseClass_to_derivedClass
{
public class Animal { }
public class Giraffe : Animal { }
public void CallMeMethod()
{
List<Animal> x;
x = new List<Giraffe>(); // This line doesn't compile
}
}