如何将Stack对象添加到我的global.asax中,以便整个应用程序可以访问它?目前我有: void Application_Start(object sender, EventArgs e){ // Global vars Application.Add("ArcadeTotalUniquePlayers", 0); Application.Add("
void Application_Start(object sender, EventArgs e) { // Global vars Application.Add("ArcadeTotalUniquePlayers", 0); Application.Add("ArcadeTotalPlays", 0); Stack<int> ArcadeLastPlayers = new Stack<int>(16);
前两个变量有效,但我不确定如何使Stack全局可访问.
你可以这样做:Application.Add("ArcadeLastPlayers", new Stack<int>());
然后
((Stack<int>)Application["ArcadeLastPlayers"]).Pop();
或者您可以创建某种全局静态,因此您不必在每次需要检索它时都将其强制转换:
namespace GlobalUtils { public static class ArcadeData { public static Stack<int> ArcadeLastPlayers = new Stack<int>(); } }
然后
GlobalUtils.ArcadeData.ArcadeLastPlayers.Pop();