Mega Code Archive

 
Categories / VB.Net / Language Basics
 

Boxing and unboxing demo

Imports System Public Class MainClass          Shared Sub Main()          Dim myIntegerVariable As Integer = 123          ' boxing          Dim myObjectVariable As Object = myIntegerVariable          Console.WriteLine("myObjectVariable: {0}", _                myObjectVariable.ToString(  ))          ' unboxing (must be explicit)          Dim anotherIntegerVariable As Integer = _               DirectCast(myObjectVariable, Integer)          Console.WriteLine("anotherIntegerVariable: {0}", _               anotherIntegerVariable)     End Sub End Class