2017-02-03 79 views
0

我有一個列表被轉換爲一個數組,然後放入一個會話 ,所以在另一個頁面中我會訪問該數組,但是當我試圖解除它時,它不會返回正確的值將會話變量作爲數組投射到一個會話

//codes from page one : 
List<string> seatNum = new List<string>(); 
string[] seatnumArray = new string[ordered]; //Ordered is a defined int variable 
seatnumArray = seatNum.ToArray(); 

//codes from page two : 
if (Session["SeatNum"] != null){ 
    lblseatname.Text = Session["SeatNum"].ToString(); 
} 

//Output view : 
System.String[] 
+1

'拆箱「不是這種情況下的正確術語。 – Agalo

回答

1

您需要Session對象轉換回列表

List<string> seatNumFromSession = Session["SeatNum"] as List<string>; 

然後,你可以再次使用它,就像任何其他目錄。

lblseatname.Text = seatNumFromSession[0]; 
+0

它返回一個異常(異常詳細信息:System.NullReferenceException:對象引用未設置爲對象的實例。) –

+0

它工作這是一個問題,從第一頁,我將列表轉換爲一個數組 –