ASP.NET 循环访问会话中存储的锯齿状数组

发布于 2024-08-23 10:22:21 字数 545 浏览 6 评论 0原文

我对 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

时光倒影 2024-08-30 10:22:21

首先声明一个锯齿状数组变量并从会话变量中转换它,如下所示:

string[][] answersJArray = (string[][])Session["answersJArray"];

然后您可以像您要​​的那样循环遍历该数组:

    for (j = 0; j < answersJArray[1].Length; j++)
    {
        label.Text = (answersJArray[1][j].ToString());
    }

First declare a jagged array variable and cast it from the session variable like so:

string[][] answersJArray = (string[][])Session["answersJArray"];

Then you can loop through the array like you were going to:

    for (j = 0; j < answersJArray[1].Length; j++)
    {
        label.Text = (answersJArray[1][j].ToString());
    }
娇纵 2024-08-30 10:22:21

不应该太难。您可以从会话中获取该对象并将其转换为字符串[]。如果它是局部变量,您可以检查它的长度并以这种方式进行迭代。我可能会误解你的问题,但是我是否遗漏了一些东西,说将变量从会话映射中取出,以便你可以将其作为强类型使用?

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?

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文