Re: IEnumerable semantics



On 24 Sep 2005 15:20:48 -0700, "elvis_the_king@xxxxxx"
<elvis_the_king@xxxxxx> wrote:

>Hi all,
>
>I am asking myself wheter IEnumerable has any inherent semantics? The
>docs seem to be very unclear to me.
>
>More specifically: When using a "foreach(...)" construct to enumerate a
>Stack, Queue oder ArrayList using the IEnumerable interface - can I
>safely make any assumptions about the order in which the elements are
>returned? That is, LIFO for a Stack, FIFO for a queue and an order
>corresponding to the indices when using an ArrayList?

IEnumerable itself is just an interface that allows iteration through
a list of items. Any implementation of IEnumerable is free to select
their own order. Hashtable implements IEnumerable even though it is
completly unordered.

Unless the documentation for a specific implementation says anything
specific about the order you can't be guaranteed anything.

I would however be very surprised if ArrayList returned items in any
other order than from first to last. Queue and Stack is another matter
though, since neither of those have any concept of first and last
element.

--
Marcus Andrén
.



Relevant Pages

  • Re: Statement on Schildt submitted to wikipedia today
    ... using memoization and a work queue: ...     take from the front of the queue ... Neither the cache nor the work queue can be construed as a stack. ... I'm NOT saying that Higher Math is a conspiracy. ...
    (comp.lang.c.moderated)
  • Re: Only one end of a stack is dynamic, the oldest item is the last removed.
    ... your stack is huge and C.P.U. intensive, just give it its own heap; ... Only one end of a stack is dynamic, the oldest item is the last removed. ... It's commonly used to refer to a LIFO queue. ... certainly done using linked lists, ...
    (microsoft.public.vc.language)
  • Re: max buffer for send?
    ... > queue system. ... you are asking the socket stack _only_ to queue the ... >> can accept that and move on, you will be a better network developer. ...
    (microsoft.public.win32.programmer.networks)
  • Re: what is a stack
    ... There's FILO and FIFO, they're both implemented as a regular old array (at ... Consider a stack of plates in a cafeteria, ... aka a queue. ...
    (comp.lang.java.programmer)

Loading