ASP.NET 循环访问会话中存储的锯齿状数组
我对 ASP.net 会话中存储的锯齿状数组有一些问题,我有一些代码创建锯齿状数组,填充它们,然后将填充的锯齿状数组存储到会话中,
protected string[][] answersJArray;
answersJArray[0] = new string[4]("test","test1","test2","test3"};
answersJArray[1] = new string[4]("test","test1","test2","test3"};
Session.Add("answersJArray", answersJArray);
我将如何循环访问会话中的每个锯齿状数组?如果他们不在会话中,我不可以执行以下操作,
for (j = 0; j < answersJArray[1].Length; j++)
{
label.Text = (answersJArray[1][j].ToString());
}
我将如何通过循环会话来执行上述操作?
谢谢
im having some problems with jagged arrays stored in session for ASP.net i have some code which creates a jagged array, them populates, and then stores this populated jagged array into session
protected string[][] answersJArray;
answersJArray[0] = new string[4]("test","test1","test2","test3"};
answersJArray[1] = new string[4]("test","test1","test2","test3"};
Session.Add("answersJArray", answersJArray);
how would i loop through each jagged array in the session ?? if they were not in session i no i could do the following
for (j = 0; j < answersJArray[1].Length; j++)
{
label.Text = (answersJArray[1][j].ToString());
}
how would i do the above by looping through the session ??
thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
首先声明一个锯齿状数组变量并从会话变量中转换它,如下所示:
然后您可以像您要的那样循环遍历该数组:
First declare a jagged array variable and cast it from the session variable like so:
Then you can loop through the array like you were going to:
不应该太难。您可以从会话中获取该对象并将其转换为字符串[]。如果它是局部变量,您可以检查它的长度并以这种方式进行迭代。我可能会误解你的问题,但是我是否遗漏了一些东西,说将变量从会话映射中取出,以便你可以将其作为强类型使用?
Shouldn't be too tough. You can get the object out of session and cast it into a string[]. If it's a local variable, you can check its length and iterate that way. I might be misunderstanding your issue, but am I missing something by saying get the variable out of the Session map, so you can work with it as a strong-type?