Covariance and Contravariance in C#, Part Two: Array Covariance

C# implements variance in two ways. Today, the broken way. Ever since C# 1.0, arrays where the element type is a reference type are covariant. This is perfectly legal: Animal[] animals = new Giraffe[10]; Since Giraffe is smaller than Animal, and “make an array of” is a covariant operation on types, Giraffe[] is smaller than … Continue reading Covariance and Contravariance in C#, Part Two: Array Covariance