public interface IDictionary<TKey,TValue>: ICollection<KeyValuePair<TKey,TValue>>, IEnumerable<KeyValuePair<TKey,TValue>>
This type implements System.Collections.Generic.ICollection<KeyValuePair<TKey,TValue>> and System.Collections.Generic.IEnumerable<KeyValuePair<TKey,TValue>>.
mscorlib
BCL
Represents a generic collection of key/value pairs.
This interface class is the base interface for generic collections of key/value pairs. The implementing class must have a method for comparing keys.Each element is a key/value pair stored in a key value pair object.
Each pair must have a non-
null
key unique according to the comparison method of the class implementing this interface. The value can benull
and need not be unique. The IDictionary<TKey,TValue> interface allows the contained keys and values to be enumerated, but it does not imply any particular sort order.Some implementations of this interface might permit null keys, and some might not. A dictionary implementation that prohibits null keys shall throw ArgumentNullException whenever a method or indexer is called with a null key.
DefaultMemberAttribute("Item")
System.Collections.Generic Namespace
IDictionary<TKey,TValue> Methods
IDictionary<TKey,TValue>.Add Method
IDictionary<TKey,TValue>.ContainsKey Method
IDictionary<TKey,TValue>.Remove Method
IDictionary<TKey,TValue> Properties
IDictionary<TKey,TValue>.Item Property
IDictionary<TKey,TValue>.Keys Property
IDictionary<TKey,TValue>.Values Property
void Add(TKey key, TValue value)
Adds an entry with the provided key and value to the current instance.
- key
- The
TKey
to use as the key of the entry to add.- value
- The
TValue
to use as the value of the entry to add.
Exception Type Condition ArgumentException An entry with the same key already exists in the current instance.
NotSupportedException The current instance is read-only.
You can also use the System.Collections.Generic.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 System.Collections.Generic.IDictionary<TKey,TValue>.Item(TKey)(TKey)
property overwrites the old value. In contrast, the System.Collections.Generic.IDictionary<TKey,TValue>.Add(TKey,TValue)(TKey,TValue)
method does not modify existing elements.Implementations can vary in how they determine equality of objects.
System.Collections.Generic.IDictionary<TKey,TValue> Interface, System.Collections.Generic Namespace
bool ContainsKey(TKey key)
Determines whether the current instance contains an entry with the specified key.
- key
- The key to locate in the current instance.
true
if the current instance contains an entry with the key; otherwise,false
.
Implementations can vary in how they determine equality of objects.
System.Collections.Generic.IDictionary<TKey,TValue> Interface, System.Collections.Generic Namespace
bool Remove(TKey key)
Removes the entry with the specified key from the current instance.
- key
- The key of the entry to remove.
true
if the element is successfully removed; otherwise,false
.[Note: This method also returnsfalse
if key was not found.]
Exception Type Condition NotSupportedException The current instance is read-only.
Implementations can vary in how they determine equality of objects.
System.Collections.Generic.IDictionary<TKey,TValue> Interface, System.Collections.Generic Namespace
TValue this[TKey key] { get; set; }
Gets or sets the element in the current instance that is associated with the specified key.
- key
- The key of the element to get or set.
The value associated with the given key.
Exception Type Condition 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 System.Collections.Generic.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 System.Collections.Generic.IDictionary<TKey,TValue>.Item(TKey)(TKey)
property overwrites the old value. In contrast, the System.Collections.Generic.IDictionary<TKey,TValue>.Add(TKey,TValue)(TKey,TValue)
method does not modify existing elements.Implementations can vary in how they determine equality of objects.
System.Collections.Generic.IDictionary<TKey,TValue> Interface, System.Collections.Generic Namespace
ICollection<TKey> Keys { get; }
Gets a collection containing the keys of the current instance.
A collection containing the keys of the current instance.
This property is read-only.The order of the keys in the returned System.Collections.Generic.ICollection<TKey> is unspecified, but it is guaranteed to be the same order as the corresponding values in the collection returned by the System.Collections.Generic.IDictionary<TKey,TValue>.Values property.
System.Collections.Generic.IDictionary<TKey,TValue> Interface, System.Collections.Generic Namespace
ICollection<TValue> Values { get; }
Gets a collection containing the values in the current instance.
A collection containing the values in the current instance.
This property is read-only.The order of the values in the returned System.Collections.Generic.ICollection<TKey> is unspecified, but it is guaranteed to be the same order as the corresponding keys in the collection returned by the System.Collections.Generic.IDictionary<TKey,TValue>.Keys property.
System.Collections.Generic.IDictionary<TKey,TValue> Interface, System.Collections.Generic Namespace