G
Guest
Hello All,
I have a 2-dimensional array that I am storing as a session variable. I have
no idea on how I can cast the session variable back to 2-dimensional array.
Any pointers?
Reference code below...
Array declaration:
DateTime[][] DateRangesForDataLists = new DateTime[5][];
Sample element population:
DateRangesForDataLists[0] = new DateTime[2];
DateRangesForDataLists[0][0] = System.DateTime.Today;
DateRangesForDataLists[0][1] = new
DateTime(System.DateTime.Today.Year,System.DateTime.Today.Month,1);
Storing in session:
Session["DataListStartEndDates"] = DateRangesForDataLists;
Trying to access from session:
private DateTime GetDateFromSession(int FirstIndex, int SecondIndex)
{
DateTime[,] DateRangesForDataLists = new DateTime[5,2];
DateRangesForDataLists = (DateTime[,])Session["DataListStartEndDates"];
return DateRangesForDataLists[FirstIndex,SecondIndex];
}
And in the above method it is giving me an error: "Specified cast is not
valid." What am I doing wrong?
Thanks for your help!!
I have a 2-dimensional array that I am storing as a session variable. I have
no idea on how I can cast the session variable back to 2-dimensional array.
Any pointers?
Reference code below...
Array declaration:
DateTime[][] DateRangesForDataLists = new DateTime[5][];
Sample element population:
DateRangesForDataLists[0] = new DateTime[2];
DateRangesForDataLists[0][0] = System.DateTime.Today;
DateRangesForDataLists[0][1] = new
DateTime(System.DateTime.Today.Year,System.DateTime.Today.Month,1);
Storing in session:
Session["DataListStartEndDates"] = DateRangesForDataLists;
Trying to access from session:
private DateTime GetDateFromSession(int FirstIndex, int SecondIndex)
{
DateTime[,] DateRangesForDataLists = new DateTime[5,2];
DateRangesForDataLists = (DateTime[,])Session["DataListStartEndDates"];
return DateRangesForDataLists[FirstIndex,SecondIndex];
}
And in the above method it is giving me an error: "Specified cast is not
valid." What am I doing wrong?
Thanks for your help!!