Global variables in windows forms

  • Thread starter Thread starter None
  • Start date Start date
N

None

Hi,

I want to maintain gloabl variables in windows forms like session
in asp.net. How can i do this. Is there anyway to do this? If anybody
knows the solution pls let me know..

Thanks and Regards,
Vinothkumar B
(e-mail address removed)
 
None,

C# doesn't allow decaling variables or methods outside of a class, but you
can always declare a public static member of a class that will be visible
anywhere the class is. Static members are *global* in a way that there is
only one instace of it.
 
Soitcho is of course correct in the sense that it can be done however as a
design rule you should never rely on global variables in your application.

You would be better to provide an interface that can be used to obtain the
current settings, variables, connection string or whatever you want to
globalize and have the main form implement this interface for example. It's
a detail that many ignore because globals are easy but these can become a
real architectural disaster when used habitually.

--
Bob Powell [MVP]
Visual C#, System.Drawing

Ramuseco Limited .NET consulting
http://www.ramuseco.com

Find great Windows Forms articles in Windows Forms Tips and Tricks
http://www.bobpowell.net/tipstricks.htm

Answer those GDI+ questions with the GDI+ FAQ
http://www.bobpowell.net/faqmain.htm

All new articles provide code in C# and VB.NET.
Subscribe to the RSS feeds provided and never miss a new article.
 
Back
Top