HybridDictionary Class

 

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

Namespace:   System.Collections.Specialized
Assembly:  System (in System.dll)

System.Object
  System.Collections.Specialized.HybridDictionary
    System.Web.Mobile.CookielessData

[<SerializableAttribute>]
type HybridDictionary = 
    class
        interface IDictionary
        interface ICollection
        interface IEnumerable
    end

NameDescription
System_CAPS_pubmethodHybridDictionary()

Creates an empty case-sensitive HybridDictionary.

System_CAPS_pubmethodHybridDictionary(Boolean)

Creates an empty HybridDictionary with the specified case sensitivity.

System_CAPS_pubmethodHybridDictionary(Int32)

Creates a case-sensitive HybridDictionary with the specified initial size.

System_CAPS_pubmethodHybridDictionary(Int32, Boolean)

Creates a HybridDictionary with the specified initial size and case sensitivity.

NameDescription
System_CAPS_pubpropertyCount

Gets the number of key/value pairs contained in the HybridDictionary.

System_CAPS_pubpropertyIsFixedSize

Gets a value indicating whether the HybridDictionary has a fixed size.

System_CAPS_pubpropertyIsReadOnly

Gets a value indicating whether the HybridDictionary is read-only.

System_CAPS_pubpropertyIsSynchronized

Gets a value indicating whether the HybridDictionary is synchronized (thread safe).

System_CAPS_pubpropertyItem(Object)

Gets or sets the value associated with the specified key.

System_CAPS_pubpropertyKeys

Gets an ICollection containing the keys in the HybridDictionary.

System_CAPS_pubpropertySyncRoot

Gets an object that can be used to synchronize access to the HybridDictionary.

System_CAPS_pubpropertyValues

Gets an ICollection containing the values in the HybridDictionary.

NameDescription
System_CAPS_pubmethodAdd(Object, Object)

Adds an entry with the specified key and value into the HybridDictionary.

System_CAPS_pubmethodClear()

Removes all entries from the HybridDictionary.

System_CAPS_pubmethodContains(Object)

Determines whether the HybridDictionary contains a specific key.

System_CAPS_pubmethodCopyTo(Array, Int32)

Copies the HybridDictionary entries to a one-dimensional Array instance at the specified index.

System_CAPS_pubmethodEquals(Object)

Determines whether the specified object is equal to the current object.(Inherited from Object.)

System_CAPS_protmethodFinalize()

Allows an object to try to free resources and perform other cleanup operations before it is reclaimed by garbage collection.(Inherited from Object.)

System_CAPS_pubmethodGetEnumerator()

Returns an IDictionaryEnumerator that iterates through the HybridDictionary.

System_CAPS_pubmethodGetHashCode()

Serves as the default hash function. (Inherited from Object.)

System_CAPS_pubmethodGetType()

Gets the Type of the current instance.(Inherited from Object.)

System_CAPS_protmethodMemberwiseClone()

Creates a shallow copy of the current Object.(Inherited from Object.)

System_CAPS_pubmethodRemove(Object)

Removes the entry with the specified key from the HybridDictionary.

System_CAPS_pubmethodToString()

Returns a string that represents the current object.(Inherited from Object.)

NameDescription
System_CAPS_pubinterfaceSystem_CAPS_privmethodIEnumerable.GetEnumerator()

Returns an IEnumerator that iterates through the HybridDictionary.

NameDescription
System_CAPS_pubmethodAsParallel()

Overloaded. Enables parallelization of a query.(Defined by ParallelEnumerable.)

System_CAPS_pubmethodAsQueryable()

Overloaded. Converts an IEnumerable to an IQueryable.(Defined by Queryable.)

System_CAPS_pubmethodCast<'TResult>()

Casts the elements of an IEnumerable to the specified type.(Defined by Enumerable.)

System_CAPS_pubmethodOfType<'TResult>()

Filters the elements of an IEnumerable based on a specified type.(Defined by Enumerable.)

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 null, but a value can.

The foreach statement of the C# language (For Each in Visual Basic) returns an object of the type of the elements 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:

No code example is currently available or this language may not be supported.

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

The following code example demonstrates several of the properties and methods of HybridDictionary.

No code example is currently available or this language may not be supported.

Universal Windows Platform
Available since 10
.NET Framework
Available since 1.1

Public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.

This implementation does not provide a synchronized (thread safe) wrapper for a HybridDictionary, but derived classes can create their own synchronized versions of the HybridDictionary using the SyncRoot property.

Enumerating through a collection is intrinsically not a thread-safe procedure. Even when a collection is synchronized, other threads can still modify the collection, which causes the enumerator to throw an exception. To guarantee thread safety during enumeration, you can either lock the collection during the entire enumeration or catch the exceptions resulting from changes made by other threads.

Return to top
Show: