Roadmap › VB.NET — Visual Basic .NET from Basics to Advanced (with C# Comparison) › Module: Errors, LINQ and Modern Features
Lessons in this course (12)
12. Converting VB.NET to C# and migration strategy
Advanced★ Must knowLesson 12 of 12
| VB.NET | C# |
|---|---|
Dim x As New List(Of Integer) | var x = new List<int>(); |
If x Is Nothing Then | if (x is null) |
For i = 0 To n - 1 | for (int i = 0; i < n; i++) |
arr(0) | arr[0] |
Dim a(9) As Integer (10 items) | var a = new int[10]; |
x \ y, x Mod y | x / y (ints), x % y |
"a" & "b" | "a" + "b" |
AndAlso / OrElse | && / || |
DirectCast(o, T) / TryCast(o, T) | (T)o / o as T |
AddHandler e, AddressOf M | e += M; |
Handles btn.Click | wire btn.Click += ... (or markup) |
Shared / Module | static / static class |
MustInherit / Overridable | abstract / virtual |
On Error Resume Next | no equivalent — rewrite with try/catch |
My.Settings | IOptions<T> / appsettings.json |
Migration strategy for a legacy VB.NET app:
- Turn on
Option Strictand fix warnings (finds hidden bugs first). - Add tests around critical behaviour.
- Mixed-language solution: new code in C# class libraries referenced by the VB project (both compile to IL).
- Convert class libraries one by one with a converter, review by hand (Mid/InStr 1-based, integer division,
Nothingsemantics for value types,On Error). - UI: Web Forms → ASP.NET Core MVC/Razor Pages or Blazor (rewrite page by page behind a reverse proxy — strangler pattern); WinForms VB can move to .NET 8/10 WinForms directly.
- Use .NET Upgrade Assistant for project files and package updates.