System.Collections.Specialized.HybridDictionary Class

Implements IDictionary by using a System.Collections.Specialized.ListDictionary while the collection is small, and then switching to a Hashtable when the collection gets large.

See Also: HybridDictionary Members


public class HybridDictionary : IDictionary


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 System.Collections.Specialized.ListDictionary with small collections, and offers the flexibility of switching to a Hashtable which handles larger collections better than System.Collections.Specialized.ListDictionary.

If the initial size of the collection is greater than the optimal size for a System.Collections.Specialized.ListDictionary, the collection is stored in a Hashtable to avoid the overhead of copying elements from the System.Collections.Specialized.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(object). 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 null, 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 System.Collections.Specialized.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:

code reference: System.Collections.Specialized.HybridDictionary2#2

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


Namespace: System.Collections.Specialized
Assembly: System (in System.dll)
Assembly Versions: 1.0.3300.0, 1.0.5000.0,,