Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Variable available to ALL classes?

Status
Not open for further replies.

Kenny100

Technical User
Feb 6, 2001
72
0
0
NZ
Hi there

I'm a bit new to C# but I'm learning ...

Is it possible to create a global variable in a C# program that is available to all classes? I don't need to modify the variable, I just need to set it once and then read from it from different classes within my program.

Cheers,
Kenny.
 
Hi,

You should create new class (ex:clsGlobal) then you declare one variable that has type static

ex: public static bool blnReadForm.

When you need access you write : clsGlobal.blnReadForm

In C# there are no global variable. You can access the static variable without its instance.

Regards,
Uyen Chi Uyen Chi
Software developer

Atlasindustries Ltd.
Viet Nam
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top