Visual Basic v Singleton Module

So, I have been programming in C # for the last 6 years or so, and now I have wet VB.net on my feet.

The code base I'm working with uses some modules. For me, the module is very similar to singleton. Only one exists; it can be called anywhere inside the namespace.

Is there something I am missing here? Does VB support the usual way of structuring a singleton object (private constructor / public instance field)?

+4
source share
2 answers

Modules are not single. This is much more like a static class in C #. If you decompile the code, you will see that they have a very similar structure (the modules have an additional attribute).

The main differences between the C # static class and the VB.Net module ...

  • No need to add static / general classifiers to methods in the module. They are separated by default, and you cannot change this.
  • If the module is in the Imported namespace, all of its methods are available without qualification.
  • Static classes in C # can be shared, modules cannot (although they can have common elements)
+6
source

If I am not mistaken, the VB module is the same as the static class.

+3
source

All Articles