gpt4 book ai didi

.net - ConcurrentDictionary 的列表顺序是否得到保证?

转载 作者:行者123 更新时间:2023-12-03 20:21:58 26 4
gpt4 key购买 nike

我正在使用 ConcurrentDictionary 来存储日志行,当我需要向用户显示它们时,我调用 ToList()生成一个列表。但奇怪的是,一些用户在列表中最先收到最近的行,而从逻辑上讲,他们应该排在最后。

这是因为 ConcurrentDictionary 不保证 IEnumerate 接口(interface)上的持久顺序,还是可能是什么原因?

最佳答案

没有 ConcurrentDictionary (和 Dictionary<T> 就此而言)不保证列表中键的顺序。您必须使用不同的数据类型或自己执行排序。对于非并发代码,您将使用 SortedDictionary<T> ,但我不相信并发集合中有类似物。

关于.net - ConcurrentDictionary 的列表顺序是否得到保证?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20020074/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com