Click to Rate and Give Feedback
MSDN
MSDN Library
Visual Studio 2008
Visual Studio
 SortedList and SortedDictionary Col...
This page is specific to
Microsoft Visual Studio 2008/.NET Framework 3.5

Other versions are also available for the following:
.NET Framework Developer's Guide
SortedList and SortedDictionary Collection Types

Updated: November 2007

The System.Collections..::.SortedList class, the System.Collections.Generic..::.SortedList<(Of <(TKey, TValue>)>) generic class, and the System.Collections.Generic..::.SortedDictionary<(Of <(TKey, TValue>)>) generic class are similar to the Hashtable class and the Dictionary<(Of <(TKey, TValue>)>) generic class in that they implement the IDictionary interface, but they maintain their elements in sort order by key, and they do not have the O(1) insertion and retrieval characteristic of hash tables. The three classes have several features in common:

The following table lists some of the differences between the two sorted list classes and the SortedDictionary<(Of <(TKey, TValue>)>) class.

SortedList nongeneric class and SortedList<(Of <(TKey, TValue>)>) generic class

SortedDictionary<(Of <(TKey, TValue>)>) generic class

The properties that return keys and values are indexed, allowing efficient indexed retrieval.

No indexed retrieval.

Retrieval is O(log n).

Retrieval is O(log n).

Insertion and removal are generally O(n); however, insertion is O(1) for data that are already in sort order, so that each element is added to the end of the list. (This assumes that a resize is not required.)

Insertion and removal are O(log n).

Uses less memory than a SortedDictionary<(Of <(TKey, TValue>)>).

Uses more memory than the SortedList nongeneric class and the SortedList<(Of <(TKey, TValue>)>) generic class.

Note:

For values that contain their own keys (for example, employee records that contain an employee ID number), you can create a keyed collection that has some characteristics of a list and some characteristics of a dictionary by deriving from the KeyedCollection<(Of <(TKey, TItem>)>) generic class.

Tags What's this?: Add a tag
Community Content   What is Community Content?
Add new content RSS  Annotations
Processing
© 2008 Microsoft Corporation. All rights reserved. Terms of Use  |  Trademarks  |  Privacy Statement
Page view tracker