System
2.0.0.0
4.0.0.0
System.Collections.IDictionary
elements can be accessed either with the key or with the index.
Each element is a key/value pair stored in a structure.
Each pair must have a unique key that is not null, but the value can be null and does not have to be unique. The interface allows the contained keys and values to be enumerated, but it does not imply any particular sort order.
The foreach statement of the C# language (For Each in Visual Basic) requires the type of each element in the collection. Because each element of the is a key/value pair, the element type is not the type of the key or the type of the value. Instead, the element type is , as the following example shows.
code reference: System.Collections.Specialized.IOrderedDictionary_Implementation#03
The foreach statement is a wrapper around the enumerator, which allows only reading from, not writing to, the collection.
Represents an indexed collection of key/value pairs.
Method
2.0.0.0
4.0.0.0
System.Collections.IDictionaryEnumerator
[Visual Basic, C#]
The foreach statement of the C# language (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, the property 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.
Returns an enumerator that iterates through the collection.
An for the entire collection.
Method
2.0.0.0
4.0.0.0
System.Void
accepts null as a valid value and allows duplicate elements.
If the parameter is equal to , the parameter is added to the end of the collection.
In collections of contiguous elements, such as lists, the elements that follow the insertion point move down to accommodate the new element. If the collection is indexed, the indexes of the elements that are moved are also updated. This behavior does not apply to collections where elements are conceptually grouped together, such as a hash table.
Inserts a key/value pair into the collection at the specified index.
The zero-based index at which the key/value pair should be inserted.
The object to use as the key of the element to add.
The object to use as the value of the element to add. The value can be null.
Property
2.0.0.0
4.0.0.0
System.Object
To be added.
To be added.
To be added.
To be added.
Method
2.0.0.0
4.0.0.0
System.Void
In collections of contiguous elements, such as lists, the elements that follow the removed element move up to occupy the vacated spot. If the collection is indexed, the indexes of the elements that are moved are also updated. This behavior does not apply to collections where elements are conceptually grouped together, such as a hash table.
Removes the element at the specified index.
The zero-based index of the element to remove.