This is a simple implementation of IDictionary using a singly linked list. It is smaller and faster than a Hashtable if the number of elements is 10 or less. This should not be used if performance is important for large numbers of elements.
Items in a ListDictionary are not in any guaranteed order; code should not depend on the current order. The ListDictionary is implemented for fast keyed retrieval; the actual internal order of items is implementation-dependent and could change in future versions of the product.
Members, such as Item, Add, Remove, and Contains are O(n) operations, where n is Count.
A key cannot be nullNothingnullptra null reference (Nothing in Visual Basic), but a value can.
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 ListDictionary 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 DictionaryEntry. For example:
foreach (DictionaryEntry de in myListDictionary) {...}
For Each de As DictionaryEntry In myListDictionary
...
Next de
The foreach statement is a wrapper around the enumerator, which only allows reading from, not writing to, the collection.