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

检索数组中的值&;存储在会话中并调用其他页面asp.net c#,asp.net,Asp.net,嗨 我想在会话中存储数组中的值。我想用它换一页。我怎么能做到? 我使用会话存储数组的值,如下所示: 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);

嗨 我想在会话中存储数组中的值。我想用它换一页。我怎么能做到? 我使用会话存储数组的值,如下所示:

    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;
这个代码是对的? 因为它没有赋予价值。 但检索到另一页时,它会给出数组的最后一个值,在同一页上,它会给出所有值。我想要数组的所有值。 Asp.net,c#
多谢各位

您可以将整个阵列存储到会话中:

Session["values"] = a;
另一页:

SomeType[] a = Session["values"] as SomeType[];
// Use the array here

您可以将整个阵列存储到会话中:

Session["values"] = a;
另一页:

SomeType[] a = Session["values"] as SomeType[];
// Use the array here
试试这个

以存储阵列的所有项

string[] a = new string[]{"a","b","c"};
Session["values"] = a;
在下一页中,您可以像这样检索它

string[] a = (string[])Session["values"]
试试这个

以存储阵列的所有项

string[] a = new string[]{"a","b","c"};
Session["values"] = a;
在下一页中,您可以像这样检索它

string[] a = (string[])Session["values"]

您面临的问题在代码的最后一行:

Response.Write(a);
就像你说的

int[].ToString() 
通常情况下,输出将与您现在的输出相同

我的目标是将数据存储为字符串数组,然后您可以这样表示它:

Response.Write(string.Join(", ", a));

您面临的问题在代码的最后一行:

Response.Write(a);
就像你说的

int[].ToString() 
通常情况下,输出将与您现在的输出相同

我的目标是将数据存储为字符串数组,然后您可以这样表示它:

Response.Write(string.Join(", ", a));

你可以把它放在一个类中,就像这样:

公共类MyGlobals

私有共享\u QuizArray作为新的ArrayList

_theArray = value
公共财产阵列作为阵列列表

_theArray = value
得到

结束

设置(ByVal值作为ArrayList)

端集

端属性

末级

然后从各种页面访问它,如下所示:

Response.Write(string.Join(", ", a));
设置值:QuizArray.Add(索引)


获取值:i=QuizArray(index)

您可以将其放入一个类中,如下所示:

公共类MyGlobals

私有共享\u QuizArray作为新的ArrayList

_theArray = value
公共财产阵列作为阵列列表

_theArray = value
得到

结束

设置(ByVal值作为ArrayList)

端集

端属性

末级

然后从各种页面访问它,如下所示:

Response.Write(string.Join(", ", a));
设置值:QuizArray.Add(索引)


Get Value:i=QuizArray(index)

我使用了它,但它给出了输出:System.Int32[]我就是这样做的。我发布了我的代码。值仍然没有出现,它给出了输出:System.Int32[]我使用了它,但它给出了输出:System.Int32[]我是这样做的。我发布了我的代码。值没有出现,但它给出了输出:System.Int32[]我以相同的方式使用,但它给出了输出:System.Int32[]。无法检索任何值。我没有找到你。你从哪里得到这个?什么是a?哦,你修改了问题。您在执行响应时获得System.Int32[],是否写入?这是因为无法直接打印数组。你需要做一个循环并尝试。试试这个。foreach(在{Response.Write(i.ToString());}中的int i仍然是System.Int32[]System.Int32[]System.Int32[]System.Int32[]System.Int32[]System.Int32[]System.Int32[]loop@Anuraj告诉我如何在函数中使用这些值。我有getquestion(int no)函数。我必须使用这些数组值来代替函数中的no。他们的方法和索引一样吗?我用了同样的方法,但它给出了输出:System.Int32[]。无法检索任何值。我没有找到你。你从哪里得到这个?什么是a?哦,你修改了问题。您在执行响应时获得System.Int32[],是否写入?这是因为无法直接打印数组。你需要做一个循环并尝试。试试这个。foreach(在{Response.Write(i.ToString());}中的int i仍然是System.Int32[]System.Int32[]System.Int32[]System.Int32[]System.Int32[]System.Int32[]System.Int32[]loop@Anuraj告诉我如何在函数中使用这些值。我有getquestion(int no)函数。我必须使用这些数组值来代替函数中的no。他们有没有办法像索引一样做到这一点?