Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Visual Basic Module v Singleton

So I've been programming in C# for the last 6 years or so and now I'm getting my feet wet with VB.net.

The code base I'm working with uses some modules. To me the module looks a lot like a singleton. Only one exists; it can be called anywhere inside the namespace.

Is there something I'm missing here? Does VB not support the normal way a singleton is structured (private constructor/public instance field)?

like image 734
Joel Barsotti Avatar asked Jan 24 '23 08:01

Joel Barsotti


1 Answers

Modules are not a singleton. It is much more akin to a static class in C#. If you decompile the code you will see they have a very similar structure (modules have an extra attribute).

The major differences between a C# static class and a VB.Net module are ...

  • Don't have to add Static / Shared qualifiers to methods in a module. They are Shared by default and you cannot change this
  • If a Module is in an Imported namespace, all of its methods are available without qualification.
  • Static classes in C# can be generic, modules cannot (although they can have generic members)
like image 178
JaredPar Avatar answered Jan 25 '23 22:01

JaredPar