Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > cannot convert from 'object' to system.array

Reply
Thread Tools

cannot convert from 'object' to system.array

 
 
=?Utf-8?B?a2x5bm4=?=
Guest
Posts: n/a
 
      05-25-2005
I defined a session variable as an array using Session["MY_SESVAR"] = new
string[200];
Later, in my code, I need to set it and sort it.
I tried Session["MY_SESVAR"][j] = "some string";
My error is "Cannot apply indexing with [] to an expression of type 'object'.
Then, later, I try to use it, and sort on it an get 'cannot convert from
'object' to System.array.
what am I doing wrong here?
 
Reply With Quote
 
 
 
 
Egghead
Guest
Posts: n/a
 
      05-25-2005
You need to put the session variable to a string array, put your "some
string" to that string array, and put it back to the "MY_SESVR".
Egghead
"klynn" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> I defined a session variable as an array using Session["MY_SESVAR"] = new
> string[200];
> Later, in my code, I need to set it and sort it.
> I tried Session["MY_SESVAR"][j] = "some string";
> My error is "Cannot apply indexing with [] to an expression of type

'object'.
> Then, later, I try to use it, and sort on it an get 'cannot convert from
> 'object' to System.array.
> what am I doing wrong here?



 
Reply With Quote
 
 
 
 
Bruce Barker
Guest
Posts: n/a
 
      05-25-2005
the session collection only holds objects, to use an object as an array you
need to cast it:

((string[]) Session["MY_SESVAR"])[j] = "some string";

though this will still blow if there is no session, you should try something
like:

string[] myStrings = Session["MY_SESVAR"] as string[];
if (myStrings == null)
setupSession();
else
myStrings[j] = "some string";



-- bruce (sqlwork.com)


"klynn" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
>I defined a session variable as an array using Session["MY_SESVAR"] = new
> string[200];
> Later, in my code, I need to set it and sort it.
> I tried Session["MY_SESVAR"][j] = "some string";
> My error is "Cannot apply indexing with [] to an expression of type
> 'object'.
> Then, later, I try to use it, and sort on it an get 'cannot convert from
> 'object' to System.array.
> what am I doing wrong here?



 
Reply With Quote
 
=?Utf-8?B?a2x5bm4=?=
Guest
Posts: n/a
 
      05-25-2005
So, what you're saying is as follows:
First setup string array
string strArr[] = new string[200];
then, set it.
then, sort it.
then, take session variable and set it to strArr
Session["MY_VAR"] = strArr
??

"Egghead" wrote:

> You need to put the session variable to a string array, put your "some
> string" to that string array, and put it back to the "MY_SESVR".
> Egghead
> "klynn" <(E-Mail Removed)> wrote in message
> news:(E-Mail Removed)...
> > I defined a session variable as an array using Session["MY_SESVAR"] = new
> > string[200];
> > Later, in my code, I need to set it and sort it.
> > I tried Session["MY_SESVAR"][j] = "some string";
> > My error is "Cannot apply indexing with [] to an expression of type

> 'object'.
> > Then, later, I try to use it, and sort on it an get 'cannot convert from
> > 'object' to System.array.
> > what am I doing wrong here?

>
>
>

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Qestion about convert Object to byte[] and convert it back davidxiongcn@gmail.com Java 5 11-04-2006 04:11 PM
IsNumeric: Convert.ToInt32 vs. Convert.ToInt64 sck10 ASP .Net 4 09-03-2006 09:40 PM
To convert to J2SE 6 or not to convert, that is the question... Jaap Java 4 07-10-2006 09:03 AM
convert list of strings to set of regexes; convert list of strings to trie Klaus Neuner Python 7 07-26-2004 07:25 AM
Do I need to Convert with Convert.ToInt32(session("myNumber")) ? Andreas Klemt ASP .Net 1 07-23-2003 02:59 PM



Advertisments