字典枚举顺序

编程入门 行业动态 更新时间:2024-10-26 10:38:09
本文介绍了字典枚举顺序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

文档显示未指定 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.

更多推荐

字典枚举顺序

本文发布于:2023-11-10 01:54:31,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1574035.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:字典   顺序

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!