ASP.NET looping through jagged array stored in session
im having some problems with jagged arrays stored in session for ASP.net i have some code which creates a jagged array, them populates, and then stores this populated jagged array into session
protected string[][] answersJArray;
answersJArray[0] = new string[4]("test","test1","test2","test3"};
answersJArray[1] = new string[4]("test","test1","test2","test3"};
Session.Add("answersJArray", answersJArray);
how would i loop through each jagged array in the session ?? if开发者_开发知识库 they were not in session i no i could do the following
for (j = 0; j < answersJArray[1].Length; j++)
{
label.Text = (answersJArray[1][j].ToString());
}
how would i do the above by looping through the session ??
thanks
First declare a jagged array variable and cast it from the session variable like so:
string[][] answersJArray = (string[][])Session["answersJArray"];
Then you can loop through the array like you were going to:
for (j = 0; j < answersJArray[1].Length; j++)
{
label.Text = (answersJArray[1][j].ToString());
}
Shouldn't be too tough. You can get the object out of session and cast it into a string[]. If it's a local variable, you can check its length and iterate that way. I might be misunderstanding your issue, but am I missing something by saying get the variable out of the Session map, so you can work with it as a strong-type?
精彩评论