Boxing and Unboxing in VB.NET
In this article I will explain you about Boxing and Unboxing in VB.NET.
Boxing and unboxing is an important concept in VB.NET's type system. With Boxing and Unboxing one can link between value-types and reference-types by allowing any value of a value-type to be converted to and from type object.
- Boxing is a mechanism in which value type is converted into reference type.
- It is implicit conversion process in which object type (super type) is used.
- In this process type and value both are stored in object type
Program to show Boxing and Unboxing:
- Unboxing is a mechanism in which reference type is converted into value.
- It is explicit conversion process.
Dim i As Integer = 10
Dim j As Integer
Dim o As Object
o = i
j = CInt(o)
Console.WriteLine("value of o object : " & o)
Console.WriteLine("Value of j : " & j)
Output of above program:
Hope the article might have helped you in understanding Boxing and Unboxing.
Your feedback and constructive contributions are welcome. Please feel free to contact me for feedback or comments you may have about this article.