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 ...
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