KeyValuePair<TKey,TValue>.Key Propriété

Définition

Obtient la clé de la paire clé/valeur.

public:
 property TKey Key { TKey get(); };
public TKey Key { get; }
member this.Key : 'Key
Public ReadOnly Property Key As TKey

Valeur de propriété

TKey

TKey qui est la clé de KeyValuePair<TKey,TValue>.

Exemples

L’exemple de code suivant montre comment énumérer les clés et les valeurs d’un dictionnaire, à l’aide de la KeyValuePair<TKey,TValue> structure.

Ce code fait partie d’un exemple plus complet fourni pour la Dictionary<TKey,TValue> classe.

// When you use foreach to enumerate dictionary elements,
// the elements are retrieved as KeyValuePair objects.
Console::WriteLine();
for each( KeyValuePair<String^, String^> kvp in openWith )
{
    Console::WriteLine("Key = {0}, Value = {1}",
        kvp.Key, kvp.Value);
}
// When you use foreach to enumerate dictionary elements,
// the elements are retrieved as KeyValuePair objects.
Console.WriteLine();
foreach( KeyValuePair<string, string> kvp in openWith )
{
    Console.WriteLine("Key = {0}, Value = {1}",
        kvp.Key, kvp.Value);
}
' When you use foreach to enumerate dictionary elements,
' the elements are retrieved as KeyValuePair objects.
Console.WriteLine()
For Each kvp As KeyValuePair(Of String, String) In openWith
    Console.WriteLine("Key = {0}, Value = {1}", _
        kvp.Key, kvp.Value)
Next kvp

Remarques

Cette propriété est en lecture seule.

S’applique à