What is the difference between these two assignments? A inherits from Base.
Base b = new A();
A c = new A();
I don’t understand why this works, if the second is declared as type A.
List<Base> vals = new List<Base>();
values.Add(b);
values.Add(c);
What should I lookup to understand this more?
Inheritance constitutes an is a relation: if
AinheritsBase, it means thatAcan go whereverBaseis allowed to go. This is precisely what your code snippet is showing: you can add an instance ofA, a subclass ofBaseto aList<Base>where any subclass ofBasecan go.