This article covers the GetType operator in VB.NET.
Often while coding a large software things can get very complicated with variables going through countless stages, new objects being created left and right etc. Often the need arises to check the type of an object or variable or perhaps compare the types of two objects to see if they are the same. With the help of the GetType Operator, we can achieve this.
GetType Demonstration
The method and purpose of this Function is pretty simple, so we’ll just demonstrate it’s use on as many VB.NET datatypes as we can think of, even some special ones like DateTime.
Module Module1
Sub Main()
Dim type1 As Integer
Dim type2 As Int16
Dim type3 As Int32
Dim type4 As Int64
Dim type5 As Short
Dim type6 As Long
Dim type7 As Single
Dim type8 As Double
Dim type9 As Decimal
Dim type10 As String = ""
Dim type11 As Char
Dim type12 As Boolean
Dim type13 As DateTime
Dim type14(0) As Integer
Console.WriteLine(type1.GetType())
Console.WriteLine(type2.GetType())
Console.WriteLine(type3.GetType())
Console.WriteLine(type4.GetType())
Console.WriteLine(type5.GetType())
Console.WriteLine(type6.GetType())
Console.WriteLine(type7.GetType())
Console.WriteLine(type8.GetType())
Console.WriteLine(type9.GetType())
Console.WriteLine(type10.GetType())
Console.WriteLine(type11.GetType())
Console.WriteLine(type12.GetType())
Console.WriteLine(type13.GetType())
Console.WriteLine(type14.GetType())
End Sub
End Module
Below is the console output of the above code.

This marks the end of the VB.NET GetType Tutorial. Any suggestions or contributions for CodersLegacy are more than welcome. Questions regarding the article content can be asked in the comments section below.