Sequentiality when using GetEnumerator on an ArrayList

  • Thread starter Thread starter DotNetED
  • Start date Start date
D

DotNetED

Hi,
If I use the GetEnumerator approach to walking through an ArrayList, is
there a guarantee that the objects in the ArrayList will be retrieved (with
<enumerator>.Current) in the same order they were added? that is, first I
will get the element at index 0, then the element at one and so on? Or is
this not specified and I can therefore get the elements in a random order?

Regards
E!
 
The enumerator for ArrayList always returns the items in order from the zero
index to the last available.

There is no guarantee that all objects will return items in that order. Most
will but the order of enumeration depends on the specific implementation of
the enumerator. It would be possible for example to create a collection that
returned the enumerated values in an order that was subject to some sorting
criteria without actually re-ordering the objects in the list.

--
Bob Powell [MVP]
Visual C#, System.Drawing

All you ever wanted to know about ListView custom drawing is in Well Formed.
http://www.bobpowell.net/currentissue.htm

Answer those GDI+ questions with the GDI+ FAQ
http://www.bobpowell.net/gdiplus_faq.htm

*RSS*RSS*RSS*RSS*RSS*RSS*RSS*RSS*RSS*RSS*RSS*RSS*RSS*

The GDI+ FAQ: http://www.bobpowell.net/faqfeed.xml
Windows Forms Tips and Tricks: http://www.bobpowell.net/tipstricks.xml
Bob's Blog: http://royo.is-a-geek.com/siteFeeder/GetFeed.aspx?FeedId=41

*RSS*RSS*RSS*RSS*RSS*RSS*RSS*RSS*RSS*RSS*RSS*RSS*RSS*
 
Back
Top