Вопрос

I have a session object in my c# class, that contains an ArrayList type of data. How can I access the array within the session object?

Given the image below, how would I access _confNum value?

enter image description here

Это было полезно?

Решение

HttpSession is a key-object store. C# is strongly typed, you need to cast the result of the []-accessor.

TripAssignment[] logs = (TripAssignment[])HttpContext.Current.Session["DriverTripLog"];
TripAssignment log = logs[0];

By the way, you shouldnt use ArrayList, if possible.

ArrayList logs = (ArrayList)HttpContext.Current.Session["DriverTripLog"];
TripAssignment log = (TripAssignment)logs[0];

Другие советы

Just cast it.

ArrayList myAL = (ArrayList)Session["DriverTripLog"];

TripAssessment myObj = myAL[0]; 
var list = Session["DriverTripLog"]!=null? (ArrayList)Session["DriverTripLog"]:null;
Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top