Covariance vs. contravariance
- by alexmac
What are the concepts of covariance and contravariance?
Given 2 classes, Animal and Elephant (which inherits from Animal), my understanding is that you get runtime errors in .NET if you try and put an Elephant into an array of Animal, which happens because Elephant is "bigger" (more specific) than Animal. But could you assign Animal to an array of Elephants as Elephant is guaranteed to contain the Animal properties?