.NET 中有排序的集合类型吗?

Is there a sorted collection type in .NET?(.NET 中有排序的集合类型吗?)
本文介绍了.NET 中有排序的集合类型吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在寻找一个能够将所有物品保持井井有条的容器.我查看了 SortedList,但这需要一个单独的键,并且不允许重复键.我也可以只使用一个未排序的容器,并在每次插入后对其进行显式排序.

I'm looking for a container that keeps all its items in order. I looked at SortedList, but that requires a separate key, and does not allow duplicate keys. I could also just use an unsorted container and explicitly sort it after each insert.

用法:

  • 偶尔插入
  • 按顺序频繁遍历
  • 最好不要使用与实际对象分开的键,使用比较函数进行排序.
  • 需要对等价对象进行稳定排序,但这不是必需的.
  • 不需要随机访问.

我意识到我可以自己构建一个平衡的树结构,我只是想知道框架是否已经包含这样的野兽.

I realize I can just build myself a balanced tree structure, I was just wondering if the framework already contains such a beast.

推荐答案

你可能想看看 Wintellect电源集合.它在 CodePlex 上可用,并且包含很多非常有用的集合.项目中的 OrderedBag 集合正是您要寻找的.它本质上使用 红黑树 来提供非常有效的排序.

You might want to take a look at the Wintellect Power Collections. It is available on CodePlex and contains quite a few collections that are very helpful. The OrderedBag collection in the project is exactly what you are looking for. It essentially uses a red-black tree to provide a pretty efficient sort.

这篇关于.NET 中有排序的集合类型吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本站部分内容来源互联网,如果有图片或者内容侵犯您的权益请联系我们删除!

相关文档推荐

DispatcherQueue null when trying to update Ui property in ViewModel(尝试更新ViewModel中的Ui属性时DispatcherQueue为空)
Drawing over all windows on multiple monitors(在多个监视器上绘制所有窗口)
Programmatically show the desktop(以编程方式显示桌面)
c# Generic Setlt;Tgt; implementation to access objects by type(按类型访问对象的C#泛型集实现)
InvalidOperationException When using Context Injection in ASP.Net Core(在ASP.NET核心中使用上下文注入时发生InvalidOperationException)
LINQ many-to-many relationship, how to write a correct WHERE clause?(LINQ多对多关系,如何写一个正确的WHERE子句?)