System.Collections Namespace
Represents a collection of key-and-value pairs.
The IDictionary class is the base interface for collections of key-and-value pairs.
Each element is a key-and-value pair stored in a DictionaryEntry object.
- Each pair must have a unique key. Implementations can vary in whether they allow the key to be a null reference (Nothing in Visual Basic).
- The value can be a null reference (Nothing in Visual Basic) and does not have to be unique.
The IDictionary interface allows the contained keys and values to be enumerated, but it does not imply any particular sort order.
IDictionary implementations fall into three categories: read-only, fixed-size, variable-size.
- A read-only IDictionary cannot be modified.
- A fixed-size IDictionary does not allow the addition or removal of elements, but it allows the modification of existing elements.
- A variable-size IDictionary allows the addition, removal and modification of elements.
The foreach statement of the C# language (for each ...next in Visual Basic) requires the type of each element in the collection. Since each element of a collection based on IDictionary is a key-and-value pair, the element type is not the type of the key or the type of the value. Instead, the element type is DictionaryEntry. For example:
foreach ( DictionaryEntry myEntry in myHashtable ) {
...
}
for each myEntry as DictionaryEntry in myHashtable
...
next |
|
C# |
VB |
Hashtable Class