Covariance vs. contravariance
Posted
by alexmac
on Stack Overflow
See other posts from Stack Overflow
or by alexmac
Published on 2008-11-07T15:26:11Z
Indexed on
2010/03/23
6:13 UTC
Read the original article
Hit count: 472
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?
© Stack Overflow or respective owner