This class is recommended for cases where the number of elements in a dictionary is unknown. It takes advantage of the improved performance of a ListDictionary with small collections, and offers the flexibility of switching to a Hashtable which handles larger collections better than ListDictionary.
If the initial size of the collection is greater than the optimal size for a ListDictionary, the collection is stored in a Hashtable to avoid the overhead of copying elements from the ListDictionary to a Hashtable.
The constructor accepts a Boolean parameter that allows the user to specify whether the collection ignores the case when comparing strings. If the collection is case-sensitive, it uses the key's implementations of Object..::.GetHashCode and Object..::.Equals. If the collection is case-insensitive, it performs a simple ordinal case-insensitive comparison, which obeys the casing rules of the invariant culture only. By default, the collection is case-sensitive. For more information on the invariant culture, see System.Globalization..::.CultureInfo.
A key cannot be nullNothingnullptra null reference (Nothing in Visual Basic), but a value can.
vb#c#
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 HybridDictionary 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 myHybridDictionary) {...}
For Each de As DictionaryEntry In myHybridDictionary
...
Next de
vb#c#
The foreach statement is a wrapper around the enumerator, which only allows reading from, not writing to, the collection.
Windows Mobile for Pocket PC, Windows Mobile for Smartphone, Windows CE Platform Note:
All keys added to a case-insensitive HybridDictionary must have string values.