本文介绍了用foreach迭代词典,这是做什么顺序?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
说我有一个字典
,我添加每个键
和 code>
现在,如果我想以后能够在相同的顺序中迭代这个 Dictionary
添加,是这个顺序我得到简单 foreach
循环在这个字典?
Say I have a
Dictionary
, and I add each key
and value
entry in a specific order.
Now, if I want later to be able to iterate this Dictionary
in the same order entries were added, is it the order I get with simple foreach
loop on this dictionary?
如果没有,我很高兴听到我该怎么做,我知道这可以很容易地与
列表
而不是字典
,但我不想。
If not, I will be glad to hear how can I do that, I know this can be done easily with
List
instead of Dictionary
but I don't want to.
感谢
推荐答案
/ code>不保证商品的订单。
Normal
Dictionary
does not guarantee order of items.
您需要,如果您要维护添加到订单项目。
You need
OrderedDictionary
if you want to maintain order items where added to it.
这篇关于用foreach迭代词典,这是做什么顺序?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!