Ishika Ishika - 10 months ago 39
ASP.NET (C#) Question

retrieving values in array & store in session and calling to other page c#

I want to store values inside the array in session. I want to use it to another page. How i can do that?
I used session to store values of array as follow:

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;


Session["values"] = a;

In other page i used code:

int[] a = (int[])Session["values"];

This code is right?
Because its not giving values.
But retrieving to another page then it gives last value of the array, on the same page it gives all the values. I want all the values of the array., c#
Thank you.

Answer Source

Try this

To store all items of the array.

string[] a = new string[]{"a","b","c"};
Session["values"] = a;

And in the next page, you can retrieve it like this.

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