Handling global information

  • Thread starter Thread starter Jan Tielens
  • Start date Start date
J

Jan Tielens

You can accomplish the same by create in class with static properties that
will act as global variables. Since the properties are static you don't need
an instance of the class, so you can use it like this:

Globals.MyVariable = "Testing";

Implementation:
public class Globals
{
static string _myVariable;

static public string MyVariable
{
get
{
return _myVariable;
}
set
{
_myVariable = value;
}
}
}


--
Greetz

Jan Tielens
________________________________
Read my weblog: http://weblogs.asp.net/jan
 
Hi,

I am using C# to develop Windows forms applications. I previously worked
with VB 6. My question involves the following scenario.

I want to create a splash screen, which on application start-up will be
displayed and at the same time load some data from a database, and do some
initialization and configuration. In VB I can have a global module where I
would declare system wide global variables which would be set during this
start-up period. How would I do this in C# given that it doesn't have global
variables.
 
Thanks Jan,

Seems obvious now.


Jan Tielens said:
You can accomplish the same by create in class with static properties that
will act as global variables. Since the properties are static you don't need
an instance of the class, so you can use it like this:

Globals.MyVariable = "Testing";

Implementation:
public class Globals
{
static string _myVariable;

static public string MyVariable
{
get
{
return _myVariable;
}
set
{
_myVariable = value;
}
}
}


--
Greetz

Jan Tielens
________________________________
Read my weblog: http://weblogs.asp.net/jan
 
Back
Top