Global variables in windows forms

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)
 
G

Greg Young

I guess "Global" would actually be more like Application than Session but
....

An easy way is to just create an object to hold them, then either keep a
static or singleton based reference to that object ..

Let's say I use a SettingsCollection to hold them ... lets just assume
settings is a Dictionary<string, object>

public static class GlobalData {
public static SettingsCollection Settings = new SettingsCollection();
}

I could then access this
GlobalData.Settings["foo"] = bar;
bar = (int) GlobalData.Settings["foo"];

Cheers,

Greg
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top