Logically, one would think that the foreach loop in C# would evaluate in the same order as an incrementing for loop. Experimentally, it does. However, there appears to be no such confirmation on the MSDN site.
Is it simply such an apparent answer that they did not think to include that information on the site? Or is there the possibility that it will behave erratically?
For arrays (note that
System.ArrayimplementsIEnumerable), it will access elements in order. For other types (IEnumerable, or havingGetEnumerator), it accesses elements in the order provided, through alternatingMoveNextandCurrentcalls.The standard states (ECMA-334 §13.9.5):