Re: IEnumerable semantics
- From: Marcus Andrén <a@xxx>
- Date: Sun, 25 Sep 2005 01:16:06 +0200
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
.
- References:
- IEnumerable semantics
- From: elvis_the_king@xxxxxx
- IEnumerable semantics
- Prev by Date: Re: Problem with Garbage Collection
- Next by Date: New & confused-Possible to inherit aspx forms?
- Previous by thread: IEnumerable semantics
- Next by thread: Re: IEnumerable semantics
- Index(es):
Relevant Pages
|
Loading