SortedList that just takes IComparable<T>

浪子不回头ぞ 提交于 2019-12-05 15:00:40

There's nothing built-in. You have some options:

  • Use SortedList with a dummy TValue.
  • Use a list or array and call List.Sort() or Array.Sort() when necessary.
  • Write your own.
  • Use a third party library

For this particular case check out Wintellect PowerCollections OrderedBag class, which uses a red-black tree internally. Other good free data structure libraries include NGenerics and C5.

Henk Holterman

If I understand correctly, you want an SortedCollection< TValue> instead of the various SortedCollection< TKey, TValue> that are there.

In .NET 4 there is a new SortedSet<T> class that keeps its items in order, but doesn't allow duplicates. Otherwise you'll have to look at 3rd party options, like the one Matt Howells mentions.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!