HybridDictionary.Add Method (Object, Object)


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

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

abstract Add : 
        key:Object *
        value:Object -> unit
override Add : 
        key:Object *
        value:Object -> unit


Type: System.Object

The key of the entry to add.

Type: System.Object

The value of the entry to add. The value can be null.

Exception Condition

key is null.


An entry with the same key already exists in the HybridDictionary.

An object that has no correlation between its state and its hash code value should typically not be used as the key. For example, String objects are better than StringBuilder objects for use as keys.

A key cannot be null, but a value can.

You can also use the Item property to add new elements by setting the value of a key that does not exist in the HybridDictionary; for example, myCollection["myNonexistentKey"] = myValue. However, if the specified key already exists in the HybridDictionary, setting the Item property overwrites the old value. In contrast, the Add method does not modify existing elements.

When the number of elements becomes greater than the optimal size for a ListDictionary, the elements are copied from the ListDictionary to a Hashtable. However, this only happens once. If the collection is already stored in a Hashtable and the number of elements falls below the optimal size for a ListDictionary, the collection remains in the Hashtable.

This method is an O(1) operation.

The following code example adds to and removes elements from a 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
Return to top