DEV Community

DIVAKAR UPADHYAY
DIVAKAR UPADHYAY

Posted on Originally published at devladder.pages.dev

Program structure, modules and the Main method — VB.NET

Lesson 1 of 12 in the free VB.NET — Visual Basic .NET from Basics to Advanced (with C# Comparison) course on DevLadder.

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
Enter fullscreen mode Exit fullscreen mode
  • 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 Helpers Module Helpers
static void Main(string[] args) Sub Main(args As String())
// comment ' comment
Console.WriteLine("x"); Console.WriteLine("x")

Interview questions on VB.NET

What is the difference between VB.NET and C#?

Both compile to the same IL and run on the same CLR with the same libraries, so performance is the same. Differences are syntax and features: VB.NET uses English-like keywords, is case-insensitive, line-based with End blocks, has XML literals, My namespace, WithEvents/Handles and optional late binding; C# uses C-style syntax, is case-sensitive and gets new language features every year while VB.NET has been feature-stable since 2020. Most new projects use C#; VB.NET is mainly maintained in legacy systems.

What do Option Strict, Option Explicit and Option Infer do?

Option Explicit On requires variables to be declared. Option Strict On disallows implicit narrowing conversions and late binding — catching type errors at compile time (strongly recommended). Option Infer On lets Dim x = 5 infer the type from the initializer. Set them per project (Compile settings) or per file at the top.

What is the difference between Sub and Function?

A Sub performs an action and returns no value (C# void method). A Function returns a value with Return (or by assigning to the function name in old code). Both can take ByVal/ByRef, Optional and ParamArray parameters.


Read the full lesson with progress tracking and the rest of the course on DevLadder — free step-by-step tutorials and interview questions for developers.

Next in the course: Data types, variables, constants and conversions →

Top comments (0)