Gets or sets the element in the current instance that is associated with the specified key.
This is the default property for this class.
public TValue this [TKey key] { set; get; }
- key
- The key of the element to get or set.
The value associated with the given key.
Type Reason ArgumentException The property is read but key is not found. NotSupportedException The property is set and the current instance is read-only.
This property provides the ability to access a specific element in the collection.
You can also use the IDictionary<TKey, TValue>.Item(TKey)(TKey) property to add new elements by setting the value of a key that does not exist in the dictionary. However, if the specified key already exists in the dictionary, setting the IDictionary<TKey, TValue>.Item(TKey)(TKey) property overwrites the old value. In contrast, the IDictionary<TKey, TValue>.Add(TKey, TValue)(TKey,TValue) method does not modify existing elements.
Implementations can vary in how they determine equality of objects.
Namespace: System.Collections.Generic
Assembly: mscorlib (in mscorlib.dll)
Assembly Versions: 2.0.0.0
Since: .NET 2.0