.NET 中有字典的替代品吗?
我需要在项目中使用字典,但我们知道它们只能使用键访问,不能使用索引,并且我想使用索引访问字典中的项目。因此,我在网上闲逛,发现了 OrderedDictionary,因为它们可以使用索引和键访问,但它们有一些 性能问题 而且我每天每分钟都在读/写字典,所以使用 OrderedDictionary 不是一个好主意。
所以最后我的问题是,是否有任何可用的替代方案可以为我提供字典的功能,并且我还可以使用索引访问它并且不会导致性能问题。
I have a requirement of using a dictionary in the project but as we know that they are only accessible using the keys and not using the indexes, and I want to access the items in dictionary using indexes. So I fiddle over the web and found out about OrderedDictionary as they are accessible using both the indexes and keys but they have some performance issue and as I am reading/writing the dictionary every minute of the day so it's not a good idea to use OrderedDictionary.
So lastly my question in here is that is there any alternative available which gives me functionality of Dictionary and I can also access it using indexes and doesn't cause a performance issue.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
SortedList
有一个属性Values
,即IList
。够了吗?仅对于小“组”元素来说它才快。与SortedDictionary
的区别在于 http://msdn.microsoft.com/en-us/library/5z658b67(v=vs.80).aspx我可以问你为什么要访问它吗“按索引”?你仍然可以用 foreach 枚举它,你知道吗?
SortedList<TKey, TValue>
has a property,Values
, that is anIList<TValue>
. Is it enough? It's fast only for small "sets" of elements. The difference withSortedDictionary
is here http://msdn.microsoft.com/en-us/library/5z658b67(v=vs.80).aspxCan I ask you why you want to access it "by index"? You can still enumerate it with foreach, you know?
为了回应您的评论,您只期望每分钟一百次更新,这是很少的工作 - 几乎没有什么。您仍然可以使用
OrderedDictionary
,性能对您来说不是问题。in response to your comment that you are only expecting a hundred updates a minute, this is very little work - practically nothing. You can still use an
OrderedDictionary
, performance will not be an issue for you.尝试排序字典
http://msdn.microsoft.com/en-us/library/f7fta44c.aspx
Try SortedDictionary
http://msdn.microsoft.com/en-us/library/f7fta44c.aspx