Understanding Implicit Conversions

Previously we discussed the System.Object class. As you might remember, this class is the root in the class hierarchy. That said, you can assign both reference types and value types to an Object instance because they both inherit from System.Object. Consider the following lines of code:

Dim anInt As Object = 10Dim onePerson As Object = New Person

The first line assigns a value type (Integer) to an Object, and the second one assigns an instance of the Person class to an Object. Visual Basic 2015 always enables such assignments because they are always safe. However, it is unsafe to try to assign an Object to a strongly typed instance, such as an instance of the Person class. This ...

Get Visual Basic 2015 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.