O'Reilly logo

Visual Basic® .NET by Example by Bob Donald, Gabriel Oancea

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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 ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required