Will the ordering of the keys be consistent with the ordering of the values?
Yes, it's guaranteed by the documentation of both IDictionary<,>.Keys
and IDictionary<,>.Values
.
Keys
documentation:
The order of the keys in the Dictionary<TKey, TValue>.KeyCollection
is unspecified, but it is the same order as the associated values in the Dictionary<TKey, TValue>.ValueCollection
returned by the Values
property.
Values
documentation:
The order of the values in the Dictionary<TKey, TValue>.ValueCollection
is unspecified, but it is the same order as the associated keys in the Dictionary<TKey, TValue>.KeyCollection
returned by the Keys
property.