检索数组中的值并在会话中存储并调用其他页面asp.net c#

Ish*_*ika 0 asp.net

嗨,我想在会话中存储数组内的值.我想将它用于另一个页面.我怎么能这样做?我使用session来存储数组的值如下:

    int i, randno;
    int[] a = new int[5];
        for ( i = 0; i < 4; i++)
        {
            int flag = 0;
            Random rnd = new Random();
            randno = rnd.Next(1, 15);
            for (int j = 0; j < i; j++)
            {
                if (a[j] == randno)
                    flag = 1;
            }
            if (flag == 0)
            {
                a[i] = randno;

            }
            else
            {
                i--;
            }

        }
Session["values"] = a;
Run Code Online (Sandbox Code Playgroud)

在其他页面中,我使用了代码:

int[] a = (int[])Session["values"];
Response.Write(a);
Run Code Online (Sandbox Code Playgroud)

这段代码是对的?因为它没有赋予价值.但是检索到另一个页面然后它给出了数组的最后一个值,在同一页面上它给出了所有的值.我想要数组的所有值.Asp.net,c#谢谢.

Anu*_*raj 5

试试这个

存储阵列的所有项目.

string[] a = new string[]{"a","b","c"};
Session["values"] = a;
Run Code Online (Sandbox Code Playgroud)

在下一页中,您可以像这样检索它.

string[] a = (string[])Session["values"]
Run Code Online (Sandbox Code Playgroud)