System.Collections.Generic.KeyValuePair<TKey,TValue> Structure

Defines a key/value pair that can be set or retrieved.

See Also: KeyValuePair<TKey,TValue> Members

Syntax

public struct KeyValuePair<TKey, TValue>

Type Parameters

TKey
Documentation for this section has not yet been entered.
TValue
Documentation for this section has not yet been entered.

Remarks

The System.Collections.Generic.Dictionary`2.Enumerator.Current property returns an instance of this type.

The foreach statement of the C# language (for each in C++, For Each in Visual Basic) requires the type of the elements in the collection. Since each element of a collection based on IDictionary`2 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 KeyValuePair`2. For example:

code reference: Generic.Dictionary#11

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

Requirements

Namespace: System.Collections.Generic
Assembly: mscorlib (in mscorlib.dll)
Assembly Versions: 2.0.0.0, 4.0.0.0
Since: .NET 2.0