May 2010
Intermediate to advanced
1272 pages
61h 18m
English
Basically covariance allows assigning strongly typed collections (such as List) of derived classes to IEnumerable collections of abstract classes. The code in Listing 21.3 shows how covariance works.
Listing 21.3 Covariance in Visual Basic 2010

If you examine Listing 21.3 you notice that the variance variable is generic of type IEnumerable(Of Object) and receives the assignment of a generic List(Of String) content, in which Object is the base class of String. Until Visual Basic 2008 this code was illegal, and therefore it would throw a compile exception. In Visual Basic 2010 this code is legal but it works only with IEnumerable(Of T) ...
Read now
Unlock full access