Frage

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

War es hilfreich?

Lösung

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];

Andere Tipps

Just cast it.

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

TripAssessment myObj = myAL[0]; 
var list = Session["DriverTripLog"]!=null? (ArrayList)Session["DriverTripLog"]:null;
Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top