What are these terms in my header anyway?
But more importantly for me, look at this code:
Lack of variance:
why a List<Bananaisn’ t a List<Fruit>
Many people initially expect the following code to compile:
List<Bananabana nas = new List<Banana>();
List<Fruitfruit = bananas;
//however, it fails to compile (from Jon Skeet's cheat sheet)
However, this should work, right??:
List <FruitmybaseFru it = new List <Fruit>();
class Banana: Fruit {}
Banana myBanana = new Banana(); //note, this is NOT a list, but an
instantiation of a derived class Banana having base class Fruit
mybaseFruit.Add (myBanana); //should work, right? Otherwise what's the
point of inheritance?
RL
But more importantly for me, look at this code:
Lack of variance:
why a List<Bananaisn’ t a List<Fruit>
Many people initially expect the following code to compile:
List<Bananabana nas = new List<Banana>();
List<Fruitfruit = bananas;
//however, it fails to compile (from Jon Skeet's cheat sheet)
However, this should work, right??:
List <FruitmybaseFru it = new List <Fruit>();
class Banana: Fruit {}
Banana myBanana = new Banana(); //note, this is NOT a list, but an
instantiation of a derived class Banana having base class Fruit
mybaseFruit.Add (myBanana); //should work, right? Otherwise what's the
point of inheritance?
RL
Comment