Module to put all the public variables and function?

  • Thread starter Thread starter Tee
  • Start date Start date
T

Tee

Hi,

In VB, we can add a module to put all the variables and functions, do we
have something similar in C#?

Thanks
 
To store data "globally" you can use a singleton object. This is an object
whose reference is available to a static method, and exists only once.
Therefore, all of it's properties are available globally without requiring
you to pass around references. I believe that Jon has a fairly good page on
the "best" ways to declare a singleton.

For methods that were "global", you can define these methods in any class as
Static methods, which means that they can be called without the developer
having to create an object (of the class type) first. The framework has
many of these.

HTH,
--- Nick
 
Nick Malik said:
To store data "globally" you can use a singleton object. This is an object
whose reference is available to a static method, and exists only once.
Therefore, all of it's properties are available globally without requiring
you to pass around references. I believe that Jon has a fairly good page on
the "best" ways to declare a singleton.

http://www.pobox.com/~skeet/csharp/singleton.html

You don't have to though - you *can* use public static variables (or
properties), if you really want to.
 
Tee,
As the others suggest, I normally use a Singleton (either an actual
Singleton or Shared methods in a Class) in VB.NET also!

It better encapsulates the variables & functions to that class, in that you
need to qualify the variables & functions with the class name, allowing you
to instantly see where the variables & functions are coming from.

With a VB.NET Module you can forgo the Module name which causes you or
subsequent programmers to be uncertain where the variable or function is
coming from...

Hope this helps
Jay
 
Back
Top