C# 访问会话对象中的数组元素
我的c类中有一个会话对象,它包含一种数据类型。如何访问会话对象中的数组 给定下图,我如何访问_confNum值 就投吧C# 访问会话对象中的数组元素,c#,asp.net,session,httpcontext,C#,Asp.net,Session,Httpcontext,我的c类中有一个会话对象,它包含一种数据类型。如何访问会话对象中的数组 给定下图,我如何访问_confNum值 就投吧 ArrayList myAL = (ArrayList)Session["DriverTripLog"]; TripAssessment myObj = myAL[0]; 就投吧 ArrayList myAL = (ArrayList)Session["DriverTripLog"]; TripAssessment myObj = myAL[0]; HttpSess
ArrayList myAL = (ArrayList)Session["DriverTripLog"];
TripAssessment myObj = myAL[0];
就投吧
ArrayList myAL = (ArrayList)Session["DriverTripLog"];
TripAssessment myObj = myAL[0];
HttpSession是一个关键对象存储。 C是强类型的,您需要强制转换[]-accessor的结果
TripAssignment[] logs = (TripAssignment[])HttpContext.Current.Session["DriverTripLog"];
TripAssignment log = logs[0];
顺便说一下,如果可能的话,你不应该使用ArrayList
ArrayList logs = (ArrayList)HttpContext.Current.Session["DriverTripLog"];
TripAssignment log = (TripAssignment)logs[0];
HttpSession是一个关键对象存储。 C是强类型的,您需要强制转换[]-accessor的结果
TripAssignment[] logs = (TripAssignment[])HttpContext.Current.Session["DriverTripLog"];
TripAssignment log = logs[0];
顺便说一下,如果可能的话,你不应该使用ArrayList
ArrayList logs = (ArrayList)HttpContext.Current.Session["DriverTripLog"];
TripAssignment log = (TripAssignment)logs[0];
在您的第一行,我收到一个错误,无法将类型“object”隐式转换为“TripAssignment[]”,这是编译器对您的问题的答案。在你的第一行,我得到了一个错误,不能隐式地将类型“object”转换为“TripAssignment[]”,这是编译器对你问题的答案。固定的