VB.Net/Development/GetType

Материал из VB Эксперт
Версия от 12:45, 26 мая 2010; Admin (обсуждение | вклад) (1 версия)
(разн.) ← Предыдущая | Текущая версия (разн.) | Следующая → (разн.)
Перейти к: навигация, поиск

Array.CreateInstance(GetType(Integer), 11) to create Array

Imports System

Public Class MainClass
    
    Shared Sub Main(ByVal args As String())
        Dim squares As Array = _
            Array.CreateInstance(GetType(Integer), 11)
        For i As Integer = 0 To 10
            squares.SetValue(i * i, i)
        Next i
        Dim txt As String = ""
        For i As Integer = 0 To 10
            Console.WriteLine( squares.GetValue(i).ToString )
        Next i
    End Sub
End Class


Get data type full name for any object

Imports System
Imports System.Data
Imports System.Collections
public class MainClass
   Shared Sub Main()
        Dim o As Object
        o = 5
        console.WriteLine(o)
        console.WriteLine(o.GetType.FullName)
        o = "Hello"
        console.WriteLine(o)
        console.WriteLine(o.GetType.FullName)
   End Sub
End Class


Get Variable Type

Imports System

Public Class MainClass
   Shared Sub Main()
      Console.WriteLine((4 / 2).GetType())
   End Sub 
End Class


Object"s GetType Method

Imports System

Public Class MainClass
  Shared Sub Main()
    Dim c As Integer
    Console.WriteLine(c.GetType())
    Console.WriteLine(c.GetType().ToString)
  End Sub
  
End Class


Use Type.GetType to get type information

Imports System
Imports System.Reflection
 
Public Class MainClass
    Shared Sub Main(  )
         Dim t As Type = Type.GetType("System.Reflection.Assembly")
         Console.WriteLine("Single type is {0}", t)
    End Sub
  
End Class