Boxing and Unboxing
The Common Type System enables implicit conversions and conversions between reference types and value types and vice versa because both inherit from System.Object
. Regarding this, there are two other particular techniques: boxing and unboxing. You often need to work with boxing and unboxing when you have methods that receive arguments of type Object
. See the tip at the end of this section for details.
Boxing
Boxing occurs when converting a value type to a reference type. In other words, boxing is when you assign a value type to an Object
. The following lines of code demonstrate boxing:
Dim calculation As Double = 14.4 + 32.12 Dim result As Object = calculation
The calculation
variable, which stores a value deriving from the ...
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.