Multi Dimensional Arrays

D

DazedAndConfused

Is the only way to searh for a value in a multi dimensional array is with a
loop?

Is a loop any less efficient then IndexOf in a single dimensional array?
 
H

Herfried K. Wagner [MVP]

DazedAndConfused said:
Is the only way to searh for a value in a multi dimensional array is with
a loop?

Yes... When using jagged arrays you can use consecutive calls to
'Array.IndexOf' for the sub arrays.
Is a loop any less efficient then IndexOf in a single dimensional array?

In general no. I suggest to read the "Remarks" section of the
'Array.IndexOf' method, which gives information about the implementation of
this method.
 
D

DazedAndConfused

Sorry to be dense, from reading remarks it sounds like IndexOf searches the
complete array, then returns the index of the first occurence, there for the
loop is more efficient any ways. Is that what you were trying to convey with
your suggestion of reading remarks?
 
C

Cor Ligthert [MVP]

Dazed,

Are you developing for old PDA's.
Otherwise you are probably talking about fractions from milliseconds.

If you have performance problems, than I would look in more sufficient
places.

Cor
 
H

Herfried K. Wagner [MVP]

DazedAndConfused said:
Sorry to be dense, from reading remarks it sounds like IndexOf searches
the complete array, then returns the index of the first occurence, there
for the loop is more efficient any ways. Is that what you were trying to
convey with your suggestion of reading remarks?

I didn't take a look at the implementation, but I doubt that this is the
case. Typically linear search will stop when the first occurance is found.
The runtime function is in O(n) for a list containing n items.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Top