Lessons in this course (12)

1. Program structure, modules and the Main method

Basic★ Must knowLesson 1 of 12
vb
Option Strict On          ' no implicit narrowing conversions or late binding — always turn on
Option Explicit On        ' every variable must be declared
Option Infer On           ' allow Dim x = 5 (type inferred)

Imports System.Text       ' = C# using

Namespace Divakar.Shop
    Module Program                       ' a Module = C# static class; members are Shared automatically
        Sub Main(args As String())
            Console.WriteLine("Hello, Divakar!")
            Dim name As String = If(args.Length > 0, args(0), "world")
            Console.WriteLine($"Welcome {name}")       ' string interpolation (VB 14)
        End Sub
    End Module
End Namespace
  • Statements end at the line break (no semicolons); use _ for explicit line continuation, though VB 10+ allows implicit continuation after operators, commas and opening brackets.
  • Comments start with ' (or REM).
  • Blocks end with End X (End If, End Sub, End Class).
  • Keywords and identifiers are case-insensitive (dim = Dim; the IDE fixes casing).
C#VB.NET
using System;Imports System
static class HelpersModule Helpers
static void Main(string[] args)Sub Main(args As String())
// comment' comment
Console.WriteLine("x");Console.WriteLine("x")