globa variable for windows C# application

  • Thread starter Thread starter Jassim Rahma
  • Start date Start date
J

Jassim Rahma

hello,

how can i write and read a global variable for the entire application in
C#?


Many Thanks,
Jassim Rahma
 
Hello, Jassim!

JR> how can i write and read a global variable for the entire application
JR> in C#?

Since you cannot define variable on the namespace level, then the solution can be creation of a class with public static variables.

internal class GlobalVars
{
public static int GlobalVar1;
public static string GlobalVar2;
}

However, you should be carefull with this vars if you're working in the multithreaded environment.
A solution here can be substitution of vars with properties, where the neede sync will happen.

--
Regards, Vadym Stetsyak
www: http://vadmyst.blogspot.com
 
Hello Jassim,

General, all common things locates in separate namespace for project, smth
like <Company>.<Project>.Common
As Vadim mentions you need to locate separate class for global variables,
and put it in your common namespace

JR> how can i write and read a global variable for the entire
JR> application in C#?
JR>
JR> Many Thanks,
JR> Jassim Rahma

---
WBR,
Michael Nemtsev :: blog: http://spaces.msn.com/laflour

"At times one remains faithful to a cause only because its opponents do not
cease to be insipid." (c) Friedrich Nietzsche
 
Back
Top