471,627 Members | 1,713 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,627 software developers and data experts.

globa variable for windows C# application


hello,

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

*** Sent via Developersdex http://www.developersdex.com ***
Feb 18 '06 #1
2 1314
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
Feb 18 '06 #2
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
Feb 18 '06 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

4 posts views Thread by Gery D. Dorazio | last post: by
1 post views Thread by Aaron | last post: by
41 posts views Thread by Miguel Dias Moura | last post: by
5 posts views Thread by Anonymous | last post: by
2 posts views Thread by Oberon | last post: by
1 post views Thread by XIAOLAOHU | last post: by
reply views Thread by leo001 | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.