Global variable ???

  • Thread starter Thread starter serge calderara
  • Start date Start date
S

serge calderara

Dear all,

What is the best way to handle global variable in .NET?

We have for instance a configuration file with certain
application parameters.
Lets say that sDataBasePath will contain the path of a
database file set in that configuration file.

Then how to declare that variable in order that it it
global to :

1- the whole assembly
2- the whole aaplication that is based on different
assembly

In VB5 for instance that variable would be declare in
a .BAS module as Global sDataBasePath as string

thanks for your answer
Regards
 
serge calderara said:
What is the best way to handle global variable in .NET?

Make it a static member of a class.
We have for instance a configuration file with certain
application parameters.
Lets say that sDataBasePath will contain the path of a
database file set in that configuration file.

That sounds like you'd want a Configuration class, with a private
member called databasePath and a public/internal property to retrieve
it. You could either make it static, or use the singleton pattern and
make it an instance variable, which would make it easier to adapt your
app later to support multiple simultaneous configurations.
Then how to declare that variable in order that it it
global to :

1- the whole assembly

Make it internal.
2- the whole aaplication that is based on different
assembly

Make it public.
 
Back
Top