Archive

Posts Tagged ‘C#’

C# 4.0: Covariance and Contravariance

April 13th, 2009

In this article I’ll try to cover one of the C# 4.0 innovations. One of the new features is covariance and contravariance on type parameters that is now supported by generic delegates and generic interfaces. First let’s see what does these words mean :)

Generally if we have some entity (interface or delegate) that is generic on type T – some Entity<T>, and two concrete entities Entity<A> and Entity<B> where B inherits from A, then there are no inheritance relationships between Entity<A> and Entity<B>. Covariance (and contravariance) adds such relationships:

Read more…

.NET , , ,