System.Collections.Generic.IDictionary<TKey,TValue> Interface

public interface IDictionary<TKey,TValue>: ICollection<KeyValuePair<TKey,TValue>>, IEnumerable<KeyValuePair<TKey,TValue>>

Base Types

This type implements System.Collections.Generic.ICollection<KeyValuePair<TKey,TValue>> and System.Collections.Generic.IEnumerable<KeyValuePair<TKey,TValue>>.

Assembly

mscorlib

Library

BCL

Summary

Represents a generic collection of key/value pairs.

Description

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 be null 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.

Attributes

DefaultMemberAttribute("Item")

See Also

System.Collections.Generic Namespace

Members

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


IDictionary<TKey,TValue>.Add Method

void Add(TKey key, TValue value)

Summary

Adds an entry with the provided key and value to the current instance.

Parameters

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.

Exceptions

Exception TypeCondition
ArgumentExceptionAn entry with the same key already exists in the current instance.

NotSupportedExceptionThe current instance is read-only.

Description

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.

See Also

System.Collections.Generic.IDictionary<TKey,TValue> Interface, System.Collections.Generic Namespace

IDictionary<TKey,TValue>.ContainsKey Method

bool ContainsKey(TKey key)

Summary

Determines whether the current instance contains an entry with the specified key.

Parameters

key
The key to locate in the current instance.

Return Value

true if the current instance contains an entry with the key; otherwise, false .

Description

Implementations can vary in how they determine equality of objects.

See Also

System.Collections.Generic.IDictionary<TKey,TValue> Interface, System.Collections.Generic Namespace

IDictionary<TKey,TValue>.Remove Method

bool Remove(TKey key)

Summary

Removes the entry with the specified key from the current instance.

Parameters

key
The key of the entry to remove.

Return Value

true if the element is successfully removed; otherwise, false .[Note: This method also returns false if key was not found.

]

Exceptions

Exception TypeCondition
NotSupportedExceptionThe current instance is read-only.

Description

Implementations can vary in how they determine equality of objects.

See Also

System.Collections.Generic.IDictionary<TKey,TValue> Interface, System.Collections.Generic Namespace

IDictionary<TKey,TValue>.Item Property

TValue this[TKey key] { get; set; }

Summary

Gets or sets the element in the current instance that is associated with the specified key.

Parameters

key
The key of the element to get or set.

Property Value

The value associated with the given key.

Exceptions

Exception TypeCondition
ArgumentExceptionThe property is read but key is not found.

NotSupportedExceptionThe property is set and the current instance is read-only.

Description

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.

See Also

System.Collections.Generic.IDictionary<TKey,TValue> Interface, System.Collections.Generic Namespace

IDictionary<TKey,TValue>.Keys Property

ICollection<TKey> Keys { get; }

Summary

Gets a collection containing the keys of the current instance.

Property Value

A collection containing the keys of the current instance.

Description

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.

See Also

System.Collections.Generic.IDictionary<TKey,TValue> Interface, System.Collections.Generic Namespace

IDictionary<TKey,TValue>.Values Property

ICollection<TValue> Values { get; }

Summary

Gets a collection containing the values in the current instance.

Property Value

A collection containing the values in the current instance.

Description

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.

See Also

System.Collections.Generic.IDictionary<TKey,TValue> Interface, System.Collections.Generic Namespace