Export (0) Print
Expand All

KeyValuePair<TKey, TValue>.Key Property

Gets the key in the key/value pair.

Namespace:  System.Collections.Generic
Assembly:  mscorlib (in mscorlib.dll)

public TKey Key { get; }

Property Value

Type: TKey
A TKey that is the key of the KeyValuePair<TKey, TValue>.

This property is read/only.

The following code example shows how to enumerate the keys and values in a dictionary, using the KeyValuePair<TKey, TValue> structure.

This code is part of a larger example provided for the Dictionary<TKey, TValue> class.


// When you use foreach to enumerate dictionary elements,
// the elements are retrieved as KeyValuePair objects.
outputBlock.Text += "\n";
foreach (KeyValuePair<string, string> kvp in openWith)
{
   outputBlock.Text += String.Format("Key = {0}, Value = {1}",
       kvp.Key, kvp.Value) + "\n";
}


Silverlight

Supported in: 5, 4, 3

Silverlight for Windows Phone

Supported in: Windows Phone OS 7.1, Windows Phone OS 7.0

XNA Framework

Supported in: Xbox 360, Windows Phone OS 7.0

For a list of the operating systems and browsers that are supported by Silverlight, see Supported Operating Systems and Browsers.

Community Additions

ADD
Show:
© 2014 Microsoft