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?
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With