472,354 Members | 1,397 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,354 software developers and data experts.

Casting session object into a 2-dimensional array

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.DateTim e.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!!

Jan 10 '06 #1
5 3794
Try:

DateTime[][] DateRangesForDataLists =
(DateTime[][])Session["DataListStartEndDates"];
karl

--
MY ASP.Net tutorials
http://www.openmymind.net/
"Diffident" <Di*******@discussions.microsoft.com> wrote in message
news:BA**********************************@microsof t.com...
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.DateTim e.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!!

Jan 10 '06 #2
Nope, it gives me the same error message.

When you observe my code, I declared the array as a jagged array but while
retrieving I am casting it to a normal 5x2 array.....is that the problem?

How can I cast it into a jagged array?

"Karl Seguin [MVP]" wrote:
Try:

DateTime[][] DateRangesForDataLists =
(DateTime[][])Session["DataListStartEndDates"];
karl

--
MY ASP.Net tutorials
http://www.openmymind.net/
"Diffident" <Di*******@discussions.microsoft.com> wrote in message
news:BA**********************************@microsof t.com...
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.DateTim e.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!!


Jan 10 '06 #3

"Diffident" <Di*******@discussions.microsoft.com> wrote in message
news:BA**********************************@microsof t.com...
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][];


Hmm, that isn't a 2-dimensional array...rather an array of arrays...thought
I'd point that out. A two dimensional array would be defined as DateTime[,]
DateRangesForDataLists, would it not? I may be wrong, haven't dealth with
2-dimensional arrays in a long time in C#....in VB.Net, though, DateTime()()
is considered an array of arrays and DateTime(,) is 2-dimensional...

Check it out, remember, I am hardly ever correct in my assumptions... :)
Especially, this early in the morning...

Mythran

Jan 10 '06 #4
how is it declared? why can't you cast it as it is declared? post some code
if you still need help.

--
Regards,
Alvin Bruney [MVP ASP.NET]

[Shameless Author plug]
The Microsoft Office Web Components Black Book with .NET
Now Available @ www.lulu.com/owc
Forth-coming VSTO.NET - Wrox/Wiley 2006
-------------------------------------------------------

"Karl Seguin [MVP]" <karl REMOVE @ REMOVE openmymind REMOVEMETOO . ANDME
net> wrote in message news:#G**************@TK2MSFTNGP12.phx.gbl...
Try:

DateTime[][] DateRangesForDataLists =
(DateTime[][])Session["DataListStartEndDates"];
karl

--
MY ASP.Net tutorials
http://www.openmymind.net/
"Diffident" <Di*******@discussions.microsoft.com> wrote in message
news:BA**********************************@microsof t.com...
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.DateTim e.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!!


Jan 10 '06 #5
I'm not sure why my code doesn't work, this code compiles fine for me:

DateTime[][] DateRangesForDataLists = new DateTime[2][];
DateRangesForDataLists[0] = new DateTime[2];
DateRangesForDataLists[0][0] = DateTime.Today;
DateRangesForDataLists[0][1] = DateTime.Today.AddYears(1);

DateRangesForDataLists[1] = new DateTime[3];
DateRangesForDataLists[1][0] = DateTime.Today;
DateRangesForDataLists[1][1] = DateTime.Today.AddYears(1);
DateRangesForDataLists[1][2] = DateTime.Today.AddYears(2);

object o = DateRangesForDataLists;

DateTime[][] back = (DateTime[][])o;

Karl

--
MY ASP.Net tutorials
http://www.openmymind.net/
"Diffident" <Di*******@discussions.microsoft.com> wrote in message
news:DB**********************************@microsof t.com...
Nope, it gives me the same error message.

When you observe my code, I declared the array as a jagged array but while
retrieving I am casting it to a normal 5x2 array.....is that the problem?

How can I cast it into a jagged array?

"Karl Seguin [MVP]" wrote:
Try:

DateTime[][] DateRangesForDataLists =
(DateTime[][])Session["DataListStartEndDates"];
karl

--
MY ASP.Net tutorials
http://www.openmymind.net/
"Diffident" <Di*******@discussions.microsoft.com> wrote in message
news:BA**********************************@microsof t.com...
> 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.DateTim e.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!!
>


Jan 10 '06 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Rajesh Abraham | last post by:
I am new to Asp world and I have a doubt as follows. I have a class called objTranslator, which I declare and initiate global.asax as follows. Session_Start csTranslator.objTranslator...
9
by: Kurt | last post by:
Hi I was trying to get this VB type code to work in C Sub SetColumns_Example( Dim ol As Outlook.Applicatio Dim MyFolder As MAPIFolde Dim itms As Item Dim itm As Objec Dim dtmStart As Date,...
1
by: Remco | last post by:
Hi, Let me try to simply explain my questions. I've created a portal site with different types of users, e.g. Portal Administrators and Normal Users. One base class SessionUser (has a enum...
8
by: Razak | last post by:
Hi, I have a class which basically do Impersonation in my web application. From MS KB sample:- ++++++++++++++++++++code starts Dim impersonationContext As...
6
by: Carlo Marchesoni | last post by:
I have an ASP.NET/C# solution, where I can perfectly cast something I stored in the session object to a class of mine (BackEnd), as this: ->be = (BackEnd)Session;<- But if I try to do the same:...
2
by: Jeff | last post by:
ASP.NET 2.0 In the business logic layer I've got the code (see CODE) below, this code gives a compile error (see ERROR) CODE: List<Messagemessages = null; messages =...
5
by: Ronald Raygun | last post by:
If I have the following class heirarchy: class A{ protected $m_type; function type(){return $this->m_type;} } class B extends A{} class C extends B{}
3
by: Mark Rae [MVP] | last post by:
"Lloyd Sheen" <a@b.cwrote in message news:uL5TPXPvIHA.1688@TK2MSFTNGP06.phx.gbl... Surely that will throw an exception because you're trying to populate a DataSet variable with an object...
2
by: =?Utf-8?B?R2Vvc3Ns?= | last post by:
Dear All, I try to change a master page in the OnPreInit in a asp.net page. (Session variable is guaranteed to have been assigned) protected override void OnPreInit(EventArgs e){ if...
4
by: AndreH | last post by:
Good day, I have the a bit of an issue with retrieving an object from php's session. I set a session variable "user" from the class User as follows: $user = new User(); // ... do some stuff...
2
by: Kemmylinns12 | last post by:
Blockchain technology has emerged as a transformative force in the business world, offering unprecedented opportunities for innovation and efficiency. While initially associated with cryptocurrencies...
0
by: Naresh1 | last post by:
What is WebLogic Admin Training? WebLogic Admin Training is a specialized program designed to equip individuals with the skills and knowledge required to effectively administer and manage Oracle...
0
jalbright99669
by: jalbright99669 | last post by:
Am having a bit of a time with URL Rewrite. I need to incorporate http to https redirect with a reverse proxy. I have the URL Rewrite rules made but the http to https rule only works for...
0
by: antdb | last post by:
Ⅰ. Advantage of AntDB: hyper-convergence + streaming processing engine In the overall architecture, a new "hyper-convergence" concept was proposed, which integrated multiple engines and...
0
by: AndyPSV | last post by:
HOW CAN I CREATE AN AI with an .executable file that would suck all files in the folder and on my computerHOW CAN I CREATE AN AI with an .executable file that would suck all files in the folder and...
0
hi
by: WisdomUfot | last post by:
It's an interesting question you've got about how Gmail hides the HTTP referrer when a link in an email is clicked. While I don't have the specific technical details, Gmail likely implements measures...
0
by: Matthew3360 | last post by:
Hi, I have been trying to connect to a local host using php curl. But I am finding it hard to do this. I am doing the curl get request from my web server and have made sure to enable curl. I get a...
0
Oralloy
by: Oralloy | last post by:
Hello Folks, I am trying to hook up a CPU which I designed using SystemC to I/O pins on an FPGA. My problem (spelled failure) is with the synthesis of my design into a bitstream, not the C++...
0
by: Carina712 | last post by:
Setting background colors for Excel documents can help to improve the visual appeal of the document and make it easier to read and understand. Background colors can be used to highlight important...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.