472,352 Members | 1,509 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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

cannot convert from 'object' to system.array

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?
Nov 19 '05 #1
3 4053
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" <kl***@discussions.microsoft.com> wrote in message
news:22**********************************@microsof t.com...
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?

Nov 19 '05 #2
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" <kl***@discussions.microsoft.com> wrote in message
news:22**********************************@microsof t.com...
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?

Nov 19 '05 #3
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" <kl***@discussions.microsoft.com> wrote in message
news:22**********************************@microsof t.com...
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?


Nov 19 '05 #4

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

Similar topics

3
by: Laura T. | last post by:
The following code is driving me so crazy, that I'm thinking it's a "feature" or a.. ....dare I say it... a BUG. I'm using VS 2003. I've created...
2
by: Dave | last post by:
Hi, I'm trying to convert a byte array to string --This works... System.BitConverter.ToString(bytes) ...
1
by: Marc | last post by:
Hi! I'm working with a C# client that calls a php web service. I've created a wrapper to call the service using .NET wsdl tool (adding a web...
8
by: Serge BRIC | last post by:
My application, written in .NET VB, tries to get a communication port handle from a TAPI object with this code: Dim vFileHandle As Byte() =...
2
by: champion | last post by:
I am the following when i try to run my java program. I have included the code below CollectionExample1.java java.util.Collection is abstract;...
8
by: =?Utf-8?B?V2hpdG5leSBLZXc=?= | last post by:
Hi there, I'm having a bit of trouble using an HRASCONN object as a class member variable inside my managed C++ class. When I call RasDial() and...
2
by: cendter | last post by:
Hi there, I am utterly confused - I have a form that starts an instance from excel and let's the user select a range. I then want to take this...
2
by: Paulo | last post by:
DataRow dr = (DataRow)ds.Tables.Rows.ItemArray; Error 1 Cannot convert type 'object' to 'System.Data.DataRow' C:\Documents and...
2
by: Fred Mellender | last post by:
I am trying to use reflection to output the fields (names and values) of an arbitrary object -- an object dump to a TreeView. It works pretty...
0
better678
by: better678 | last post by:
Question: Discuss your understanding of the Java platform. Is the statement "Java is interpreted" correct? Answer: Java is an object-oriented...
1
by: Kemmylinns12 | last post by:
Blockchain technology has emerged as a transformative force in the business world, offering unprecedented opportunities for innovation and...
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...
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...
0
by: antdb | last post by:
Ⅰ. Advantage of AntDB: hyper-convergence + streaming processing engine In the overall architecture, a new "hyper-convergence" concept was...
0
by: Arjunsri | last post by:
I have a Redshift database that I need to use as an import data source. I have configured the DSN connection using the server, port, database, 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...
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...
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....

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.