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

Casting Reference Types by Using DirectCast

When you work with custom classes, the need to convert derived reference types to their base types is quite common. Consider the DerivedClass, which inherits from AClass. You define an object variable of the type AClass, but assign an instance of the DerivedClass to it. This is what makes polymorphism such a powerful programming technique (see Chapter 10).

Now you need a function that is provided only by DerivedClass. Because you are dealing with an instance of this class, the necessary function is generally available—but you can’t access it with the object variable that you’re using. The DirectCast method lets you set the reference to the object instance to point to an object variable of the “correct” ...

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