469,289 Members | 2,100 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,289 developers. It's quick & easy.

Looping thru Arrays

I have Type System.Object and the value is {System.Array}
I see [0].......[100] in the watch window.

How do I traverse such a data structure.

thanks for any help.
Nov 16 '05 #1
2 1123
At 20:08:25, 27.04.2004, Krish wrote:
I have Type System.Object and the value is {System.Array}
I see [0].......[100] in the watch window.

How do I traverse such a data structure.

thanks for any help.


You'll have to know the type of the base element. If it is object:

foreach(object obj in myArray)
{
// use obj
}

An alternative, using random access (indexing):

for (int i = 0; i < myArray.Length; i++)
{
// use myArray[i]
}

--
Rudy Velthuis

"If the automobile had followed the same development cycle as the
computer, a Rolls-Royce would today cost $100, get a million miles
per gallon, and explode once a year, killing everyone inside."
-- Robert X. Cringely.
Nov 16 '05 #2

"Krish" wrote...
I have Type System.Object and the
value is {System.Array}
I see [0].......[100] in the watch window.

How do I traverse such a data structure.


Say that the variable name of your object is o, you can simply do:

Array a = (Array) o;
foreach (object x in a)
{
// Do something with x
}

You would probably want to know what type the array is containing as well,
e.g.:

Type t = ((Array)o).GetValue(0).GetType();

// Bjorn A
Nov 16 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

2 posts views Thread by ensnare | last post: by
5 posts views Thread by Craig G | last post: by
4 posts views Thread by Sjoerd | last post: by
11 posts views Thread by motion musso aka: sathia | last post: by
2 posts views Thread by pob | last post: by
1 post views Thread by assgar | last post: by
reply views Thread by suresh191 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.