Understanding Implicit Conversions
Previously we discussed the System.Object
class. As you may remember, such a 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 = 10 Dim onePerson As Object = New Person
The first line assigns a value type (Integer
) to an Object
whereas the second one assigns an instance of the Person
class to an Object
. Visual Basic 2010 always enables such assignments because they are always safe. What is unsafe is trying to assign an Object
to a strongly typed instance, such as assigning Object
to an instance of the Person
class. This is quite obvious, ...
Get Visual Basic® 2010 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.