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, ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access