【发布时间】:2018-09-24 12:03:32
【问题描述】:
您好,我正在创建一个 Web 应用程序,其中我有一个会话,该会话由我的数组字符串组成,我想在该特定会话中添加更多项目
if (System.Web.HttpContext.Current.Session["Questions"] == null)
{
System.Web.HttpContext.Current.Session["Questions"] = Questions; // here question is string array,
//assigning value of array to session if session is null
}
else
{
for (var i = 0; i < ((string[])System.Web.HttpContext.Current.Session["Questions"]).Length; i++)
{
// what i need to do to push other item in the present session array
//wants to add Question here
}
}
【问题讨论】:
-
不要使用数组——它不会增长。并且永远不要添加到您正在迭代的集合中。
-
您不能将项目添加到数组中。检查此链接stackoverflow.com/questions/1440265/…
标签: c# arrays asp.net-mvc session