System 2.0.0.0 4.0.0.0 System.Object System.Collections.Generic.ICollection<System.Collections.Generic.KeyValuePair<TKey,TValue>> System.Collections.Generic.IDictionary<TKey,TValue> System.Collections.Generic.IEnumerable<System.Collections.Generic.KeyValuePair<TKey,TValue>> System.Collections.IDictionary System.Diagnostics.DebuggerDisplay("Count={Count}") System.Diagnostics.DebuggerTypeProxy(typeof(System.Collections.Generic.CollectionDebuggerView`2)) System.Runtime.InteropServices.ComVisible(false) To be added. To be added.

The generic class is an array of key/value pairs with O(log ) retrieval, where n is the number of elements in the dictionary. In this, it is similar to the generic class. The two classes have similar object models, and both have O(log ) retrieval. Where the two classes differ is in memory use and speed of insertion and removal:

uses less memory than .

has faster insertion and removal operations for unsorted data, O(log ) as opposed to O() for .

If the list is populated all at once from sorted data, is faster than .

Another difference between the and classes is that supports efficient indexed retrieval of keys and values through the collections returned by the and properties. It is not necessary to regenerate the lists when the properties are accessed, because the lists are just wrappers for the internal arrays of keys and values. The following code shows the use of the property for indexed retrieval of values from a sorted list of strings:

code reference: Generic.SortedList#11

is implemented as an array of key/value pairs, sorted by the key. Each element can be retrieved as a object.

Key objects must be immutable as long as they are used as keys in the . Every key in a must be unique. A key cannot be null, but a value can be, if the type of values in the list, , is a reference type.

requires a comparer implementation to sort and to perform comparisons. The default comparer checks whether the key type implements and uses that implementation, if available. If not, checks whether the key type implements . If the key type does not implement either interface, you can specify a implementation in a constructor overload that accepts a parameter.

The capacity of a is the number of elements the can hold. As elements are added to a , the capacity is automatically increased as required by reallocating the internal array. The capacity can be decreased by calling or by setting the property explicitly. Decreasing the capacity reallocates memory and copies all the elements in the .

For very large objects, you can increase the maximum capacity to 2 billion elements on a 64-bit system by setting the enabled attribute of the gcAllowVeryLargeObjects configuration element to true in the run-time environment.

The foreach statement of the C# language (for each in C++, For Each in Visual Basic) requires the type of the elements in the collection. Since the elements of the are key/value pairs, the element type is not the type of the key or the type of the value. Instead, the element type is . For example:

code reference: Generic.SortedList#12

The foreach statement is a wrapper around the enumerator, which only allows reading from, not writing to, the collection.

Represents a collection of key/value pairs that are sorted by key based on the associated implementation.

- Constructor
  2.0.0.0
  4.0.0.0

  Every key in a must be unique according to the default comparer.

  This constructor uses the default value for the initial capacity of the . To set the initial capacity, use the constructor. If the final size of the collection can be estimated, specifying the initial capacity eliminates the need to perform a number of resizing operations while adding elements to the .

  This constructor uses the default comparer for . To specify a comparer, use the constructor. The default comparer checks whether the key type implements and uses that implementation, if available. If not, checks whether the key type implements . If the key type does not implement either interface, you can specify a implementation in a constructor overload that accepts a parameter.

  This constructor is an O(1) operation.

  Initializes a new instance of the class that is empty, has the default initial capacity, and uses the default .

- Constructor
  2.0.0.0
  4.0.0.0
  To be added.
  To be added.
  To be added.
- Constructor
  2.0.0.0
  4.0.0.0
  To be added.
  To be added.
  To be added.
- Constructor
  2.0.0.0
  4.0.0.0

  Every key in a must be unique according to the default comparer.

  The capacity of a is the number of elements that the can hold before resizing. As elements are added to a , the capacity is automatically increased as required by reallocating the internal array.

  If the size of the collection can be estimated, specifying the initial capacity eliminates the need to perform a number of resizing operations while adding elements to the .

  The capacity can be decreased by calling or by setting the property explicitly. Decreasing the capacity reallocates memory and copies all the elements in the .

  This constructor uses the default comparer for . To specify a comparer, use the constructor. The default comparer checks whether the key type implements and uses that implementation, if available. If not, checks whether the key type implements . If the key type does not implement either interface, you can specify a implementation in a constructor overload that accepts a parameter.

  This constructor is an O() operation, where is .

  Initializes a new instance of the class that is empty, has the specified initial capacity, and uses the default .

  The initial number of elements that the can contain.
- Constructor
  2.0.0.0
  4.0.0.0
  To be added.
  To be added.
  To be added.
  To be added.
- Constructor
  2.0.0.0
  4.0.0.0
  To be added.
  To be added.
  To be added.
  To be added.
- Method
  2.0.0.0
  4.0.0.0
  System.Void `` `` To be added. To be added. To be added. To be added.
- Property
  2.0.0.0
  4.0.0.0
  System.Int32 To be added.

  is the number of elements that the can store. is the number of elements that are actually in the .

  is always greater than or equal to . If exceeds while adding elements, the capacity is increased by automatically reallocating the internal array before copying the old elements and adding the new elements.

  The capacity can be decreased by calling or by setting the property explicitly. When the value of is set explicitly, the internal array is also reallocated to accommodate the specified capacity.

  Retrieving the value of this property is an O(1) operation; setting the property is an O() operation, where is the new capacity.

  Gets or sets the number of elements that the can contain.

- Method
  2.0.0.0
  4.0.0.0
  System.Void

  is set to zero, and references to other objects from elements of the collection are also released.

  remains unchanged. To reset the capacity of the , call or set the property directly. Trimming an empty sets the capacity of the to the default capacity.

  This method is an O() operation, where is .

  Removes all elements from the .

- Property
  2.0.0.0
  4.0.0.0
  System.Collections.Generic.IComparer<TKey> To be added.

  Retrieving the value of this property is an O(1) operation.

  Gets the for the sorted list.

- Method
  2.0.0.0
  4.0.0.0
  System.Boolean `` To be added. To be added. To be added. To be added.
- Method
  2.0.0.0
  4.0.0.0
  System.Boolean `` To be added. To be added. To be added. To be added.
- Property
  2.0.0.0
  4.0.0.0
  System.Int32 To be added.

  is the number of elements that the can store. is the number of elements that are actually in the .

  is always greater than or equal to . If exceeds while adding elements, the capacity is increased by automatically reallocating the internal array before copying the old elements and adding the new elements.

  Retrieving the value of this property is an O(1) operation.

  Gets the number of key/value pairs contained in the .

- Method
  2.0.0.0
  4.0.0.0
  System.Collections.Generic.IEnumerator<System.Collections.Generic.KeyValuePair<TKey,TValue>>

  The foreach statement of the C# language (for each in C++, For Each in Visual Basic) hides the complexity of the enumerators. Therefore, using foreach is recommended, instead of directly manipulating the enumerator.

  Enumerators can be used to read the data in the collection, but they cannot be used to modify the underlying collection.

  The dictionary is maintained in a sorted order using an internal tree. Every new element is positioned at the correct sort position, and the tree is adjusted to maintain the sort order whenever an element is removed. While enumerating, the sort order is maintained.

  Initially, the enumerator is positioned before the first element in the collection. At this position, is undefined. Therefore, you must call to advance the enumerator to the first element of the collection before reading the value of .

  returns the same object until is called. sets to the next element.

  If passes the end of the collection, the enumerator is positioned after the last element in the collection and returns false. When the enumerator is at this position, subsequent calls to return false. If the last call to returned false, is undefined. You cannot set to the first element of the collection again; you must create a new enumerator instance instead.

  An enumerator remains valid as long as the collection remains unchanged. If changes are made to the collection, such as adding, modifying, or deleting elements, the enumerator is irrecoverably invalidated and its behavior is undefined.

  The enumerator does not have exclusive access to the collection; therefore, enumerating through a collection is intrinsically not a thread-safe procedure. To guarantee thread safety during enumeration, you can lock the collection during the entire enumeration. To allow the collection to be accessed by multiple threads for reading and writing, you must implement your own synchronization.

  Default implementations of collections in are not synchronized.

  This method is an O(1) operation.

  Returns an enumerator that iterates through the .

  An of type for the .

- Method
  2.0.0.0
  4.0.0.0
  System.Int32 `` To be added. To be added. To be added. To be added.
- Method
  2.0.0.0
  4.0.0.0
  System.Int32 `` To be added. To be added. To be added. To be added.
- Property
  2.0.0.0
  4.0.0.0
  TValue `` To be added. To be added. To be added. To be added.
- Property
  2.0.0.0
  4.0.0.0
  System.Collections.Generic.IList<TKey> To be added.

  The order of the keys in the is the same as the order in the .

  The returned is not a static copy; instead, the refers back to the keys in the original . Therefore, changes to the continue to be reflected in the .

  The collection returned by the property provides an efficient way to retrieve keys by index. It is not necessary to regenerate the list when the property is accessed, because the list is just a wrapper for the internal array of keys. The following code shows the use of the property for indexed retrieval of keys from a sorted list of elements with string keys:

  code reference: Generic.SortedList#11

  Retrieving the value of this property is an O(1) operation.

  Gets a collection containing the keys in the , in sorted order.

- Method
  2.0.0.0
  4.0.0.0
  System.Boolean `` To be added. To be added. To be added. To be added.
- Method
  2.0.0.0
  4.0.0.0
  System.Void ``

  This method performs a binary search; however, the elements are moved up to fill in the open spot, so this method is an O() operation, where is .

  Removes the element at the specified index of the .

  The zero-based index of the element to remove.
- Method
  2.0.0.0
  4.0.0.0
  System.Void `` To be added. To be added. To be added.
- Method
  2.0.0.0
  4.0.0.0
  System.Void To be added. To be added.
- Method
  2.0.0.0
  4.0.0.0
  System.Boolean `` To be added. To be added. To be added. To be added.
- Method
  2.0.0.0
  4.0.0.0
  System.Void `` `` To be added. To be added. To be added. To be added.
- Property
  2.0.0.0
  4.0.0.0
  System.Boolean To be added. To be added. To be added.
- Method
  2.0.0.0
  4.0.0.0
  System.Boolean `` To be added. To be added. To be added. To be added.
- Property
  2.0.0.0
  4.0.0.0
  System.Collections.Generic.ICollection<TKey> To be added. To be added. To be added.
- Property
  2.0.0.0
  4.0.0.0
  System.Collections.Generic.ICollection<TValue> To be added. To be added. To be added.
- Method
  2.0.0.0
  4.0.0.0
  System.Collections.Generic.IEnumerator<System.Collections.Generic.KeyValuePair<TKey,TValue>> To be added. To be added. To be added.
- Method
  2.0.0.0
  4.0.0.0
  System.Void `` ``

  If the type of the source cannot be cast automatically to the type of the destination , the non-generic implementations of throw , whereas the generic implementations throw .

  This method is an O() operation, where is .

  Copies the elements of the to an , starting at a particular index.

  The one-dimensional that is the destination of the elements copied from . The must have zero-based indexing. The zero-based index in at which copying begins.
- Property
  2.0.0.0
  4.0.0.0
  System.Boolean To be added.

  Default implementations of collections in are not synchronized.

  Enumerating through a collection is intrinsically not a thread-safe procedure. To guarantee thread safety during enumeration, you can lock the collection during the entire enumeration. To allow the collection to be accessed by multiple threads for reading and writing, you must implement your own synchronization.

  The property returns an object that can be used to synchronize access to the . Synchronization is effective only if all threads lock this object before accessing the collection.

  Retrieving the value of this property is an O(1) operation.

  Gets a value indicating whether access to the is synchronized (thread safe).

- Property
  2.0.0.0
  4.0.0.0
  System.Object To be added.

  Default implementations of collections in are not synchronized.

  Enumerating through a collection is intrinsically not a thread-safe procedure. To guarantee thread safety during enumeration, you can lock the collection during the entire enumeration. To allow the collection to be accessed by multiple threads for reading and writing, you must implement your own synchronization.

  The property returns an object that can be used to synchronize access to the . Synchronization is effective only if all threads lock this object before accessing the collection. The following code shows the use of the property for C#, C++, and Visual Basic.

  `ICollection ic = ...; lock (ic.SyncRoot) { // Access the collection. }` `Dim ic As ICollection = ... SyncLock ic.SyncRoot ' Access the collection. End SyncLock` `ICollection^ ic = ...; try { Monitor::Enter(ic->SyncRoot); // Access the collection. } finally { Monitor::Exit(ic->SyncRoot); }`

  Retrieving the value of this property is an O(1) operation.

  Gets an object that can be used to synchronize access to the .

- Method
  2.0.0.0
  4.0.0.0
  System.Void `` ``

  You can also use the property to add new elements by setting the value of a key that does not exist in the dictionary; for example, myCollection["myNonexistentKey"] = myValue. However, if the specified key already exists in the dictionary, setting the property overwrites the old value. In contrast, the method does not modify existing elements.

  This method is an O() operation for unsorted data, where is . It is an O(log ) operation if the new element is added at the end of the list. If insertion causes a resize, the operation is O().

  Adds an element with the provided key and value to the .

  The to use as the key of the element to add. The to use as the value of the element to add.
- Method
  2.0.0.0
  4.0.0.0
  System.Boolean ``

  This method returns false if is of a type that is not assignable to the key type of the .

  This method is an O(log ) operation, where is .

  Determines whether the contains an element with the specified key.

  true if the contains an element with the key; otherwise, false.

  The key to locate in the .
- Method
  2.0.0.0
  4.0.0.0
  System.Collections.IDictionaryEnumerator

  The foreach statement of the C# language (for each in C++, For Each in Visual Basic) hides the complexity of the enumerators. Therefore, using foreach is recommended, instead of directly manipulating the enumerator.

  Enumerators can be used to read the data in the collection, but they cannot be used to modify the underlying collection.

  Initially, the enumerator is positioned before the first element in the collection. also brings the enumerator back to this position. At this position, is undefined. Therefore, you must call to advance the enumerator to the first element of the collection before reading the value of .

  returns the same object until either or is called. sets to the next element.

  If passes the end of the collection, the enumerator is positioned after the last element in the collection and returns false. When the enumerator is at this position, subsequent calls to also return false. If the last call to returned false, is undefined. To set to the first element of the collection again, you can call followed by .

  An enumerator remains valid as long as the collection remains unchanged. If changes are made to the collection, such as adding, modifying, or deleting elements, the enumerator is irrecoverably invalidated and its behavior is undefined.

  The enumerator does not have exclusive access to the collection; therefore, enumerating through a collection is intrinsically not a thread-safe procedure. To guarantee thread safety during enumeration, you can lock the collection during the entire enumeration. To allow the collection to be accessed by multiple threads for reading and writing, you must implement your own synchronization.

  Default implementations of collections in are not synchronized.

  This method is an O(1) operation.

  Returns an for the .

  An for the .

- Property
  2.0.0.0
  4.0.0.0
  System.Boolean To be added.

  A collection with a fixed size does not allow the addition or removal of elements after the collection is created, but it allows the modification of existing elements.

  A collection with a fixed size is simply a collection with a wrapper that prevents adding and removing elements; therefore, if changes are made to the underlying collection, including the addition or removal of elements, the fixed-size collection reflects those changes.

  Retrieving the value of this property is an O(1) operation.

  Gets a value indicating whether the has a fixed size.

- Property
  2.0.0.0
  4.0.0.0
  System.Boolean To be added.

  A collection that is read-only does not allow the addition, removal, or modification of elements after the collection is created.

  A collection that is read-only is simply a collection with a wrapper that prevents modifying the collection; therefore, if changes are made to the underlying collection, the read-only collection reflects those changes.

  Retrieving the value of this property is an O(1) operation.

  Gets a value indicating whether the is read-only.

- Property
  2.0.0.0
  4.0.0.0
  System.Object `` To be added. To be added. To be added. To be added.
- Property
  2.0.0.0
  4.0.0.0
  System.Collections.ICollection To be added.

  The order of the keys in the is the same as the order in the .

  Retrieving the value of this property is an O(1) operation.

  Gets an containing the keys of the .

- Method
  2.0.0.0
  4.0.0.0
  System.Void ``

  This method performs a binary search; however, the elements are moved up to fill in the open spot, so this method is an O() operation, where is .

  Removes the element with the specified key from the .

  The key of the element to remove.
- Property
  2.0.0.0
  4.0.0.0
  System.Collections.ICollection To be added.

  The order of the values in the is the same as the order in the .

  Retrieving the value of this property is an O(1) operation.

  Gets an containing the values in the .

- Method
  2.0.0.0
  4.0.0.0
  System.Collections.IEnumerator

  The foreach statement of the C# language (for each in C++, For Each in Visual Basic) hides the complexity of the enumerators. Therefore, using foreach is recommended, instead of directly manipulating the enumerator.

  Enumerators can be used to read the data in the collection, but they cannot be used to modify the underlying collection.

  Initially, the enumerator is positioned before the first element in the collection. also brings the enumerator back to this position. At this position, is undefined. Therefore, you must call to advance the enumerator to the first element of the collection before reading the value of .

  returns the same object until either or is called. sets to the next element.

  If passes the end of the collection, the enumerator is positioned after the last element in the collection and returns false. When the enumerator is at this position, subsequent calls to also return false. If the last call to returned false, is undefined. To set to the first element of the collection again, you can call followed by .

  An enumerator remains valid as long as the collection remains unchanged. If changes are made to the collection, such as adding, modifying, or deleting elements, the enumerator is irrecoverably invalidated and its behavior is undefined.

  The enumerator does not have exclusive access to the collection; therefore, enumerating through a collection is intrinsically not a thread-safe procedure. To guarantee thread safety during enumeration, you can lock the collection during the entire enumeration. To allow the collection to be accessed by multiple threads for reading and writing, you must implement your own synchronization.

  Default implementations of collections in are not synchronized.

  This method is an O(1) operation.

  Returns an enumerator that iterates through a collection.

  An that can be used to iterate through the collection.

- Method
  2.0.0.0
  4.0.0.0
  System.Void

  This method can be used to minimize a collection's memory overhead if no new elements will be added to the collection. The cost of reallocating and copying a large can be considerable, however, so the method does nothing if the list is at more than 90 percent of capacity. This avoids incurring a large reallocation cost for a relatively small gain.

  This method is an O() operation, where is .

  To reset a to its initial state, call the method before calling method. Trimming an empty sets the capacity of the to the default capacity.

  The capacity can also be set using the property.

  Sets the capacity to the actual number of elements in the , if that number is less than 90 percent of current capacity.

- Method
  2.0.0.0
  4.0.0.0
  System.Boolean `` `` To be added. To be added. To be added. To be added. To be added.
- Property
  2.0.0.0
  4.0.0.0
  System.Collections.Generic.IList<TValue> To be added.

  The order of the values in the is the same as the order in the .

  The returned is not a static copy; instead, the refers back to the values in the original . Therefore, changes to the continue to be reflected in the .

  The collection returned by the property provides an efficient way to retrieve values by index. It is not necessary to regenerate the list when the property is accessed, because the list is just a wrapper for the internal array of values. The following code shows the use of the property for indexed retrieval of values from a sorted list of strings:

  code reference: Generic.SortedList#11

  Retrieving the value of this property is an O(1) operation.

  Gets a collection containing the values in the .