KeyValuePair Generic Structure
Assembly: mscorlib (in mscorlib.dll)
'Declaration <SerializableAttribute> _ Public Structure KeyValuePair(Of TKey, TValue) 'Usage Dim instance As KeyValuePair(Of TKey, TValue)
J# supports the use of generic types and methods, but not the declaration of new ones.
JScript does not support generic types and methods.
Not applicable.
Type Parameters
- TKey
The type of the key.
- TValue
The type of the value.
The Dictionary.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 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. For example:
The foreach statement is a wrapper around the enumerator, which allows only reading from, not writing to, the collection.
The following code example shows how to enumerate the keys and values in a dictionary, using the KeyValuePair structure.
This code is part of a larger example provided for the Dictionary class.
Windows 98, Windows Server 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile for Pocket PC, Windows Mobile for Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
The Microsoft .NET Framework 3.0 is supported on Windows Vista, Microsoft Windows XP SP2, and Windows Server 2003 SP1.