Why are entries in addition order in a .Net Dictionary?

前端 未结 11 623
死守一世寂寞
死守一世寂寞 2020-12-04 01:26

I just saw this behaviour and I\'m a bit surprised by it...

If I add 3 or 4 elements to a Dictionary, and then do a \"For Each\" to get all the keys, they appear in

11条回答
  •  慢半拍i
    慢半拍i (楼主)
    2020-12-04 02:13

    A dictionary retrieves items in hashed order. The fact that they came out in insertion order was a total coincidence.

    The MSDN documentation says:

    The order of the keys in the KeyCollection is unspecified, but it is the same order as the associated values in the ValueCollection returned by the Values property.

提交回复
热议问题