Reputation: 25302
Documentation says Dictionary
keys order is unspecified. I guess it means the first added element may be not first during enumeration. But does Dictionary
guarantee order to be the same each time I enumerate it?
Upvotes: 15
Views: 4682
Reputation: 437366
Yes, currently it does return items in the same order (assuming that you don't trigger a resize of the hashtable in the meantime).
No, you should not depend on it.
Generally speaking, unless there is an explicit guarantee that the order remains the same, then you cannot assume anything. And such a guarantee most certainly is not given:
The order in which the items are returned is undefined.
If you are interested in the details for academic purposes, see this excellent blog post.
Upvotes: 26