Working with GetType in VB.NET

GetType use to get fully qualified information of an object including namespace and its type.
  • 8348

This is an interesting article that will help you get information about type of object and description about your object that you used. It is also beneficial to extract type of methods and fields in your code. It is also give information about your run time object, when you don't know which type of object used in run time. Full name get the fully qualified name of the System.Type. It includes the namespace but not its assembly.

img.gif

Code

Module Module1
    Sub Main()
        Dim A As Short = 0
        Dim B As Integer = 0
        Dim C As Int64 = Nothing
        Dim D As Single = 0
        Dim E As Double = 0
        Dim F As Char = ControlChars.NullChar
        Dim G As Byte = 0
        Dim H As SByte = 0
        Dim I As UShort = 0
        Dim J As UInteger = 0
        Dim K As Long = 0
        Dim L As ULong = 0
        Dim M As Decimal = 0
        Dim N As String = ""
        Dim O As Boolean = True
        Console.WriteLine("short  :   {0} ", A.[GetType]().FullName)
        Console.WriteLine("int    :   {0} ", B.[GetType]().FullName)
        Console.WriteLine("Int64  :   {0} ", C.[GetType]().FullName)
        Console.WriteLine("float  :   {0} ", D.[GetType]().FullName)
        Console.WriteLine("double :   {0} ", E.[GetType]().FullName)
        Console.WriteLine("char   :   {0} ", F.[GetType]().FullName)
        Console.WriteLine("byte   :   {0} ", G.[GetType]().FullName)
        Console.WriteLine("sbyte  :   {0} ", H.[GetType]().FullName)
        Console.WriteLine("ushort :   {0} ", I.[GetType]().FullName)
        Console.WriteLine("uint   :   {0} ", J.[GetType]().FullName)
        Console.WriteLine("long   :   {0} ", K.[GetType]().FullName)
        Console.WriteLine("ulong  :   {0} ", L.[GetType]().FullName)
        Console.WriteLine("decimal:   {0} ", M.[GetType]().FullName)
        Console.WriteLine("string :   {0} ", N.[GetType]().FullName)
        Console.WriteLine("bool   :   {0} ", O.[GetType]().FullName)
        Console.ReadLine()
    End Sub
End Module

Output

output.gif
 

Categories

More Articles

© 2020 DotNetHeaven. All rights reserved.