SortedList
A sorted list is a collection that holds a set of key-value pairs. The keys and values are stored in two sorted arrays. This allows the list to function both as an array (indexed access to values) as well as a sorted list (search based on the keys).
A sorted list may not contain duplicate keys. A hash table can have duplicate keys.
The SortedList implements the IDictionary and ICollection interfaces. It has similar methods to the Hashtable, and the same requirements for the keys: They must implement IComparable, or a custom comparator implementing IComparer must be added. The capacity of the list increases as required to accommodate new items added.
The same example used in the preceding section can be modified to use a SortedList ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access