The order of elements in Dictionary

The order of elements in a dictionary is non-deterministic. The notion of order simply is not defined for hashtables. So don’t rely on enumerating in the same order as elements were added to the dictionary. That’s not guaranteed.

Quote from the doc:

For purposes of enumeration, each item in the dictionary is treated as a KeyValuePair<TKey, TValue> structure representing a value and its key. The order in which the items are returned is undefined.

Leave a Comment