Skip to Content
Introducing .NET 4.0: with Visual Studio 2010
book

Introducing .NET 4.0: with Visual Studio 2010

by Alex Mackey
February 2010
Beginner content levelBeginner
400 pages
11h 13m
English
Apress
Content preview from Introducing .NET 4.0: with Visual Studio 2010

3.5. Variance

Variance has changed in .NET 4.0. At the 2008 PDC, Anders Hejlsberg (lead architect of C#) summarized the changes to variance as "[allowing] you to do things in your code that previously you were surprised you couldn't do."

For those who are already comfortable with the concept of variance (stop looking so smug), here is the short version of what has changed in .NET 4.0:

  • You can now mark parameters in generic interfaces and delegates with the out keyword to make them covariant, and with the in keyword to make them contravariant (In and Out in VB.NET).

  • The in/out keywords have been added to some commonly used generic interface and delegate types to now enable them to support safe co- and contravariance (e.g., IEnumerable<out t>

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

ASP.NET 3.5 For Dummies®

ASP.NET 3.5 For Dummies®

Ken Cox
ASP.NET 4 Unleashed

ASP.NET 4 Unleashed

Stephen Walther, Kevin Hoffman, Nate Dudek

Publisher Resources

ISBN: 9781430224556Purchase book