Global Variable

E

Elmo Watson

I have a handfull of variables that I'd like to make Global to my
application
In the old VB6 days, I'd create a Module, and put them there, accessible
from any form in the application

However, in VS.Net 2005, I added a module, and it acts somewhat like a
class, in that, to access a Public variable, there, I must precede the
variable name with the module name, like:
mdlVars.MyVar

Is this pretty much how it's done, or, if not, what's a more acceptible
approach?
 
B

Bryan Phillips

The module is the best place for it but you can still live up the old
days by adding an import to the project with the full name of your
module (including the namespace).
 
A

AlexS

I would suggest class with static members and related properties

Something like this

public class Globals {
internal static <type> globVar1;
...

public static <type> Var1 {
get {
return globVar1;
}
}
....
}

Then you can get your global like this:

myVar = Globals.Var1;

You can compile class into dll or use directly in the app.

Alex
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top