Data Types in VB .NET

In this section I’ll discuss here about value types, initialization, type information and type conversion:

Value Types
-------------------------------------
Boolean
Byte, SByte
Char
Short, UShort, Integer, UInteger, Long, ULong
Single, Double
Decimal
Date
Reference Types
Object
String

Initializing
-------------------------------------------------------------
Dim correct As Boolean = True
Dim b As Byte = &H2A   'hex
Dim o As Byte = &O52   'octal
Dim person As Object = Nothing
Dim name As String = "Dwight"
Dim grade As Char = "B"c
Dim today As Date = #12/31/2007 12:15:00 PM#
Dim amount As Decimal = 35.99@
Dim gpa As Single = 2.9!
Dim pi As Double = 3.14159265
Dim lTotal As Long = 123456L
Dim sTotal As Short = 123S
Dim usTotal As UShort = 123US
Dim uiTotal As UInteger = 123UI
Dim ulTotal As ULong = 123UL 

Type Information
-------------------------------------------------------------
Dim x As Integer 
Console.WriteLine(x.GetType())          ' Prints System.Int32 
Console.WriteLine(GetType(Integer))   ' Prints System.Int32 
Console.WriteLine(TypeName(x))        ' Prints Integer

Type Conversion
--------------------------------------------------------------
float d = 3.5f; 
int i = (int)d; // set to 3  (truncates decimal)

Add a Comment