By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
431,650 Members | 753 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 431,650 IT Pros & Developers. It's quick & easy.

Global variable ???

P: n/a
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
Jul 19 '05 #1
Share this Question
Share on Google+
1 Reply


P: n/a
serge calderara <se*************@maillefer.net> wrote:
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.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet/
If replying to the group, please do not mail me too
Jul 19 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.