Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Shouldn't there be a SortedList<T>? #126958

Unanswered
alexandrehtrb asked this question in General
Discussion options

I was looking at SortedList and I noticed that it actually is a kind of Dictionary, the difference being that a SortedList allows duplicate and null "keys", whilst a Dictionary does not.

But for use cases where the key and the value are the same element, the SortedList uses more memory, as it allocates arrays for both keys and values. A SortedList<T> would be more efficient. Shouldn't there be one?

I was unsure of opening an issue for this, so I started as a discussion.

You must be logged in to vote

Replies: 2 comments 2 replies

Comment options

You can actually use SortedSet<T>.

You must be logged in to vote
2 replies
Comment options

SortedSet<T> doesn't allow repeated items and doesn't have indexes...

Comment options

In that case, List<T> with BinarySearch would be the common practice.

Comment options

If you feel like there should be an explicit SortedList<T> to avoid the overhead of SortedList<T, T> or SortedList<T, byte> then feel free to open a proposal.

There's always one more collection type that could be exposed and most of them could be provided by external libraries instead. It being in the core libraries really depends on need/demand.

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

AltStyle によって変換されたページ (->オリジナル) /