Actually, if in doubt I'd just RTM. Test cases aren't proof positive:
I've seen someone argue that Dictionary preserves sort order because a
test case says so. Simple fact is that Dictionary *sometimes* preserves
sort order, either by conincidence or small data sets... who knows.
As stated, most "standard" (if that term apples) inbuilt sets iterate
strictly forwards... but you can normally check, for instance
Array.GetEnumerator() [which underpins the foreach compiler support]:
http://msdn2.microsoft.com/en-us/lib...numerator.aspx
<quote>
Initially, the enumerator is positioned before the first element in the
collection. Reset also brings the enumerator back to this position.
<snip/>
Current returns the same object until either MoveNext or Reset is
called. MoveNext sets Current to the next element.
<snip/>
If MoveNext passes the end of the collection, the enumerator is
positioned after the last element in the collection and MoveNext
returns false.
</quote>
This translates as "foreach goes from 0 to Length-1"
However, as pointed out by William, not all enumerators do this. You
can define for instance infinite enumerators (fibonacci numbers
perhaps? random numbers? annoying paperclip messages?), or a single set
can support multiple enumerators (via separate accessor properties /
methods), such as .GetEnumerator(), ReverseOrder.GetEnumerator(),
AlphabeticalOrder.GetEnumerator(), whatever. These would have to be
defined by whatever class implements them, of course ;-p
Marc