O'Reilly logo

Microsoft® Visual Basic® 2010 Developer’s Handbook by Klaus Löffelmann and Sarika Calla Purohit

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Type Variance

Within the context of object-oriented programming, type variance means that an object variable of a certain type can also point to an instance of a derivate of this type (covariance) or that an object variable of a derived class type can point to an instance of its base class (contravariance).

You can see a simple example of covariance in polymorphism for overridden methods of a base class. For example, if a ListBox in your Items collection expects variables of the type Object, you can also pass types derived from Object. In this case, Object behaves as a covariant.

However, there is a problem with collections. Suppose that you have a base type called BaseClass and a type derived from it called DerivedClass. As you know already, you ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required