Represents a collection of key/value pairs that are sorted by the keys and are accessible by key and by index.
Assembly: mscorlib (in mscorlib.dll)
Thetype exposes the following members.
|SortedList()||Initializes a new instance of the class that is empty, has the default initial capacity, and is sorted according to the IComparable interface implemented by each key added to the object.|
|SortedList(IComparer)||Initializes a new instance of the class that is empty, has the default initial capacity, and is sorted according to the specified IComparer interface.|
|SortedList(IDictionary)||Initializes a new instance of the class that contains elements copied from the specified dictionary, has the same initial capacity as the number of elements copied, and is sorted according to the IComparable interface implemented by each key.|
|SortedList(Int32)||Initializes a new instance of the class that is empty, has the specified initial capacity, and is sorted according to the IComparable interface implemented by each key added to the object.|
|SortedList(IComparer, Int32)||Initializes a new instance of the class that is empty, has the specified initial capacity, and is sorted according to the specified IComparer interface.|
|SortedList(IDictionary, IComparer)||Initializes a new instance of the class that contains elements copied from the specified dictionary, has the same initial capacity as the number of elements copied, and is sorted according to the specified IComparer interface.|
|Capacity||Gets or sets the capacity of a object.|
|Count||Gets the number of elements contained in a object.|
|IsFixedSize||Gets a value indicating whether a object has a fixed size.|
|IsReadOnly||Gets a value indicating whether a object is read-only.|
|IsSynchronized||Gets a value indicating whether access to a object is synchronized (thread safe).|
|Item||Gets and sets the value associated with a specific key in a object.|
|Keys||Gets the keys in a object.|
|SyncRoot||Gets an object that can be used to synchronize access to a object.|
|Values||Gets the values in a object.|
|Add||Adds an element with the specified key and value to a object.|
|Clear||Removes all elements from a object.|
|Clone||Creates a shallow copy of a object.|
|Contains||Determines whether a object contains a specific key.|
|ContainsKey||Determines whether a object contains a specific key.|
|ContainsValue||Determines whether a object contains a specific value.|
|CopyTo||Copies elements to a one-dimensional Array object, starting at the specified index in the array.|
|Equals(Object)||Determines whether the specified Object is equal to the current Object. (Inherited from Object.)|
|Finalize||Allows an object to try to free resources and perform other cleanup operations before it is reclaimed by garbage collection. (Inherited from Object.)|
|GetByIndex||Gets the value at the specified index of a object.|
|GetEnumerator||Returns an IDictionaryEnumerator object that iterates through a object.|
|GetHashCode||Serves as a hash function for a particular type. (Inherited from Object.)|
|GetKey||Gets the key at the specified index of a object.|
|GetKeyList||Gets the keys in a object.|
|GetType||Gets the Type of the current instance. (Inherited from Object.)|
|GetValueList||Gets the values in a object.|
|IndexOfKey||Returns the zero-based index of the specified key in a object.|
|IndexOfValue||Returns the zero-based index of the first occurrence of the specified value in a object.|
|MemberwiseClone||Creates a shallow copy of the current Object. (Inherited from Object.)|
|Remove||Removes the element with the specified key from a object.|
|RemoveAt||Removes the element at the specified index of a object.|
|SetByIndex||Replaces the value at a specific index in a object.|
|Synchronized||Returns a synchronized (thread-safe) wrapper for a object.|
|ToString||Returns a string that represents the current object. (Inherited from Object.)|
|TrimToSize||Sets the capacity to the actual number of elements in a object.|
|AsParallel||Enables parallelization of a query. (Defined by ParallelEnumerable.)|
|AsQueryable||Converts an IEnumerable to an IQueryable. (Defined by Queryable.)|
|Cast(TResult)||Casts the elements of an IEnumerable to the specified type. (Defined by Enumerable.)|
|OfType(TResult)||Filters the elements of an IEnumerable based on a specified type. (Defined by Enumerable.)|
For the generic version of this collection, see System.Collections.Generic.SortedList(TKey, TValue).
A object internally maintains two arrays to store the elements of the list; that is, one array for the keys and another array for the associated values. Each element is a key/value pair that can be accessed as a DictionaryEntry object. A key cannot be a null reference (Nothing in Visual Basic), but a value can be.
The capacity of a object is the number of elements the can hold. As elements are added to a , the capacity is automatically increased as required through reallocation. The capacity can be decreased by calling TrimToSize or by setting the Capacity property explicitly.
The elements of a object are sorted by the keys either according to a specific IComparer implementation specified when the is created or according to the IComparable implementation provided by the keys themselves. In either case, a does not allow duplicate keys.
The index sequence is based on the sort sequence. When an element is added, it is inserted into in the correct sort order, and the indexing adjusts accordingly. When an element is removed, the indexing also adjusts accordingly. Therefore, the index of a specific key/value pair might change as elements are added or removed from the object.
Operations on a object tend to be slower than operations on a Hashtable object because of the sorting. However, the offers more flexibility by allowing access to the values either through the associated keys or through the indexes.
Elements in this collection can be accessed using an integer index. Indexes in this collection are zero-based.
The foreach statement of the C# language (for each in Visual Basic) requires the type of each element in the collection. Since each element of the object is a key/value pair, the element type is not the type of the key or the type of the value. Rather, the element type is DictionaryEntry. For example:
The foreach statement is a wrapper around the enumerator, which allows only reading from, not writing to, the collection.
Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows XP SP2 x64 Edition, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2
The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.
Public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.
A object can support multiple readers concurrently, as long as the collection is not modified. To guarantee the thread safety of the , all operations must be done through the wrapper returned by the Synchronized method.
Enumerating through a collection is intrinsically not a thread-safe procedure. Even when a collection is synchronized, other threads can still modify the collection, which causes the enumerator to throw an exception. To guarantee thread safety during enumeration, you can either lock the collection during the entire enumeration or catch the exceptions resulting from changes made by other threads.