Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to store array in session in ASP.NET MVC?

Can you please tell me how to store an array in session and how to retrieve that array from session?

I am trying to store one array of type Double and assigning values of the same type but it is showing me an error. How do I assign values to the array which is in session?

I am using ASP.NET MVC.

like image 553
mary Avatar asked Mar 12 '10 08:03

mary


2 Answers

    Session["your_array"] = new double[]{1.0,2.0,3.0};


 double[] arr = double[](Session["your_array"]);
like image 139
chugh97 Avatar answered Oct 19 '22 23:10

chugh97


You have probably worked out how to get the double array in, but may be having some trouble getting them back out - so here are examples of both:

        double[] myDoubleArray = new double[] { 1.0, 1.2, 1.3, 1.4};
        Session["DoubleList"] = myDoubleArray;

        double[] sessionDoubles = (double[])Session["DoubleList"];
like image 28
Fenton Avatar answered Oct 19 '22 23:10

Fenton