VB.Net/Development/GetType — различия между версиями
Admin (обсуждение | вклад) м (1 версия) |
Admin (обсуждение | вклад) м (1 версия) |
(нет различий)
|
Текущая версия на 15:45, 26 мая 2010
Содержание
Array.CreateInstance(GetType(Integer), 11) to create Array
<source lang="vbnet"> 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
</source>
Get data type full name for any object
<source lang="vbnet"> 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
</source>
Get Variable Type
<source lang="vbnet"> Imports System
Public Class MainClass
Shared Sub Main() Console.WriteLine((4 / 2).GetType()) End Sub
End Class
</source>
Object"s GetType Method
<source lang="vbnet"> 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
</source>
Use Type.GetType to get type information
<source lang="vbnet"> 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
</source>