473,321 Members | 1,708 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

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

When is an array not an array?

I was enumerating a collection and printing the value of
each data item when I noticed that some of the objects in
the collection returned "System.Object[]" from
their .ToString() method.

Assuming that they aren't literally strings with the
value "System.Object[]", how can I convert one of these
objects to an object array? Reflection?
Convert.ChangeType?

My code:

DirectoryEntry parent = new DirectoryEntry
(@"LDAP://RootDSE");

IEnumerator bob =
parent.Properties.PropertyNames.GetEnumerator();
while(bob.MoveNext()){
if(parent.Properties[bob.Current.ToString
()].Value.GetType().IsArray){
Response.Write("my array: " + parent.Properties
[bob.Current.ToString()].Value.ToString());
}
}

JER
Nov 15 '05 #1
2 2361
Jerry Negrelli <je************@removethispartdatascientific.com > wrote:
I was enumerating a collection and printing the value of
each data item when I noticed that some of the objects in
the collection returned "System.Object[]" from
their .ToString() method.

Assuming that they aren't literally strings with the
value "System.Object[]", how can I convert one of these
objects to an object array? Reflection?
Convert.ChangeType?


Just cast to object[]. You don't need to convert the objects at all -
they *are* arrays.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 15 '05 #2
I'd tried that but was getting an invalid cast exception
at runtime. It turns out there is also a byte array in
the collection, so casting the byte array to an object
array is what was causing the error.

Thanks Jon!

Jerry
-----Original Message-----
Jerry Negrelli <je************@removethispartdatascientific.com > wrote:
I was enumerating a collection and printing the value of each data item when I noticed that some of the objects in the collection returned "System.Object[]" from
their .ToString() method.

Assuming that they aren't literally strings with the
value "System.Object[]", how can I convert one of these objects to an object array? Reflection?
Convert.ChangeType?


Just cast to object[]. You don't need to convert the

objects at all -they *are* arrays.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
.

Nov 15 '05 #3

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

Similar topics

10
by: Noah Spitzer-Williams | last post by:
Hello guys, I'm itinerating through my array using pointers in this fashion: image is unsigned char image do { cout << "image byte is: " << *image << endl;
1
by: mdub317 | last post by:
I'm totally new to programming and I am wondering; when would be a good time to use an array or an indexer? I want to know what types of applications would make good use of arrays or indexers. ...
2
by: david | last post by:
Well, as a matter of fact I_HAD_MISSED a basic thing or two, anyway, although Ollie's answer makes perfectly sense when dealing with classes, it doesn't seem to me to apply as well if you have to...
13
by: Kantha | last post by:
Hi all, I have declared an Union as follows typedef union { struct interrupt_bits { unsigned char c_int_hs_fs_status : 1, c_setup_intflag : 1,
3
by: ZMan | last post by:
The following code won't compile with gcc version 3.4.2 (mingw-special). How come? Error: cannot convert `char (*)' to `char**' /**********************************************************/...
1
by: DJG79 | last post by:
Hi all, I am using an open source menu that i found and it works great, except for one thing that when the web page is not scrolled to the very top the drop down links will not stay visible. Has...
5
by: comp.lang.php | last post by:
// NEW 11/27/2006: FINALLY, IF YOU ADDED OR DELETED OR DID ANY KIND OF FORM ACTION SUCCESSFULLY, DON'T RE-DISPLAY THE NEW EXPENSE ITEMS VIA $_POST if ($_POST && (!is_array($leaseObj->errorArray)...
5
by: Mercy | last post by:
I guess my C++ is pretty darn rusty. I was just looking over sample C++ code for practice... and I'm kind of confused about this code fragment: int sector2; int i = 3; memset(sector2,...
12
by: lawrence k | last post by:
I've a form that starts off like this: <form method="post" action="profile.php? id=5&formName=my_story_edit.htm" enctype="multipart/form-data"> <p>Email address:<br /> <input type="text"...
1
anfetienne
by: anfetienne | last post by:
i have this code below that i made....it loads vars from txt file splits it then puts it into an array....once in an array it the brings the pics in from the array to create thumbnails and a larger...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

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.