Roadmap › VB.NET — Visual Basic .NET from Basics to Advanced (with C# Comparison) › Module: VB.NET Basics
Lessons in this course (12)
2. Data types, variables, constants and conversions
Basic★ Must knowLesson 2 of 12
| VB.NET | C# | .NET type | Literal |
|---|---|---|---|
Integer | int | Int32 | 42, 42I |
Long | long | Int64 | 42L |
Short / Byte | short / byte | Int16 / Byte | 42S |
Double / Single | double / float | Double / Single | 1.5R / 1.5F |
Decimal | decimal | Decimal | 1.5D |
Boolean | bool | Boolean | True / False |
Char | char | Char | "A"c |
String | string | String | "text" |
Date | DateTime | DateTime | #10/24/2026# (M/d/yyyy) |
Object | object | Object |
vb
Dim count As Integer = 10
Dim price = 99.5D ' Decimal, inferred with Option Infer On
Const TaxRate As Decimal = 0.18D
Dim total As Decimal = price * (1 + TaxRate)
Dim nothingYet As String = Nothing ' Nothing = C# null (or default for value types)
Dim maybe As Integer? = Nothing ' Nullable(Of Integer)
' Conversions
Dim n1 As Integer = CInt("42") ' VB conversion keyword (rounds to even for decimals: CInt(2.5) = 2)
Dim n2 As Integer = Integer.Parse("42")
Dim ok As Boolean = Integer.TryParse(input, n1)
Dim d As Double = CDbl(n1)
Dim s As String = n1.ToString()
Dim o As Object = "hello"
Dim str As String = DirectCast(o, String) ' cast, throws if wrong type (C# (string)o)
Dim str2 As String = TryCast(o, String) ' returns Nothing if wrong type (C# o as string)
Dim v = CType(o, String) ' general conversionOption Strict On — the most important setting: it forbids implicit narrowing conversions (Dim i As Integer = 3.7 fails) and late binding on Object. With it Off, VB silently converts types and resolves members at runtime — a source of hidden bugs. Turn it on for every project (Project Properties → Compile).