字典枚举顺序 [英] Dictionary enumeration order

查看:43
本文介绍了字典枚举顺序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

文档显示未指定 Dictionary 按键顺序.我想这意味着在枚举期间第一个添加的元素可能不是第一个.但是 Dictionary 是否保证每次我枚举顺序都相同?

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).

不,您不应依赖它.

通常来说,除非明确保证顺序保持不变,否则您不能假设任何内容.而且肯定没有这样的保证没有给出:

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.

这篇关于字典枚举顺序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆