Sina Ronaghi
Sina Ronaghi

Reputation: 15

Casting a Session variable as an array

I have a list that is converted to an array then put into a session so in another page i would access to that array but when I'm trying to unbox it, it would not return a correct value

//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[]

Upvotes: 0

Views: 2818

Answers (2)

Sina Ronaghi
Sina Ronaghi

Reputation: 15

It worked it was a problem from page one that i converted a list into an array `

`//codes from page one :
    List<string> seatNum = new List<string>();
    string[] seatnumArray = new string[ordered]; //Ordered is a defined int variable
 //codes from page two :
    List<string> seatNumFromSession = Session["SeatNum"] as List<string>;
    lblseatname.Text = seatNumFromSession[0];

Upvotes: 0

VDWWD
VDWWD

Reputation: 35554

You need to convert the Session object back to a List

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

Then you can use it again as you would any other List.

lblseatname.Text = seatNumFromSession[0];

Upvotes: 1

Related Questions