Eric Meijer was talking to Scott Hanselman about the Reactive Framework in one of Scott's recent podcasts, and one of the things that Eric said was that, in .NET 4.0, IEnumerable is covariant, but in .NET 3.5 IEnumerable is not.
What this means is that, if you have a Banana
object that inherits from Fruit
, you can assign the banana to a Fruit variable, but you cannot pass an IEnumerable
of bananas to a method expecting a fruit IEnumerable in .NET 3.5, because IEnumerable is not covariant.
From the podcast:
If I have an array of bananas, I can
post that where you need an array of
fruit because banana is a sub-type of
fruit so if I have an array of bananas
and you need an array of fruit I can
pass you that array. Now, if you
expect an enumerable of fruit, I
cannot pass you an enumerable of
bananas because enumerable until .NET
4.0 was not covariant. So the fact that even though banana is a special
kind of fruit, an enumerable of banana
was not an enumerable of fruit.