Hi there,
While I agree that having global variables is a good thing to avoid, I don't agree you can't have them in a Web app. Add the following to the Code Behind of your Global.asax file:
Code:
namespace Your.Namespace
{
public class Global : System.Web.HttpApplication
{
private static int someVariable = 0;
public static int SomeVariable
{
get
{
return someVariable;
}
set
{
someVariable = value;
}
}
// Rest of Global class here
}
}
This sets up a shared (static) property for the entire application.
You can then use it like this in a page:
Your.Namespace.Global.SomeVariable = SomeValue;
Notice that this code isn't thread-safe, so you'll likely run into synchronization issues between threads. You'll need to write additional code to make this work well...
Imar
---------------------------------------
Imar Spaanjaars
Everyone is unique, except for me.