How would I add a Stack
object into my global.asax
so it's accessible by the entire application? At the moment I have:
void Application_Start(object sender, EventArgs e)
{
// Global vars
Application.Add("ArcadeTotalUniquePlayers", 0);
Application.Add("ArcadeTotalPlays", 0);
Stack<int> ArcadeLastPlayers = new Stack<int>(16);
The first two variables work, but I'm not sure how to make the Stack
globally accessible.
You could do:
Application.Add("ArcadeLastPlayers", new Stack<int>());
and then
((Stack<int>)Application["ArcadeLastPlayers"]).Pop();
Or you could make some sort of global static, so you don't have to cast it every time you need to retrieve it:
namespace GlobalUtils {
public static class ArcadeData {
public static Stack<int> ArcadeLastPlayers = new Stack<int>();
}
}
and then
GlobalUtils.ArcadeData.ArcadeLastPlayers.Pop();
If you want use the HttpApplcationState, you should be able to just do the following:
Application.Add("ArcadeLastPlayers", new Stack<int>(16));
HttpApplicationState takes a string for the name and an object as the associated value. All you would have to do is cast it to a Stack when you retrieve the "ArcadeLastPlayers" value.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With