Co- and Contravariance

Most of the C# 4.0 language features deal with dynamic typing and simplifying interoperability scenarios, but one other feature did make it in to the language update. Generic co- and contravariance is a powerful feature with a scary name. Luckily, you won’t have to deal with it directly that often. Instead, this new feature makes working with certain generic interfaces and delegates easier. Let’s have a look.

Get C# 5.0 Unleashed now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.