VB.Net/Language Basics/Boxing UnBoxing — различия между версиями

Материал из VB Эксперт
Перейти к: навигация, поиск
м (1 версия)
 
м (1 версия)
 
(нет различий)

Текущая версия на 15:42, 26 мая 2010

Boxing and unboxing demo

<source lang="vbnet"> 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


      </source>