What is the difference between a Module and a Class in VB.NET?

VB.NET Language Basic 1–2 Yrs2–3 Yrs Conceptual 1 min read

Quick Answer

A Module in VB.NET is like a C# static class — you can't instantiate it and all members are shared. But its members are also globally accessible within the namespace without qualifying with the module name. A Class is a normal type you instantiate.

A Module is VB.NET's version of a static class — no instances, everything is shared. The distinctive thing is that the members are visible globally within the namespace, so a function in Module Utilities can be called just by its name without Utilities. in front. That's convenient but it clutters the namespace. A Class is a regular type you create instances of. These days I'd lean toward a normal class with Shared methods that you have to qualify, because it's clearer where things come from.

  • Module members: Public Sub Helper() in Module Utils can be called as just Helper() anywhere in the namespace — convenient but pollutes the global scope.
  • Historically used for the app entry point (Sub Main) and shared utility functions.
  • Modern preference: a normal class with Shared members, called with the class name, for clarity.