KeyValuePair<TKey,TValue>.Key Propriedade

Definição

Obtém a chave do par chave/valor.

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

Valor da propriedade

TKey

Um TKey que é a chave do KeyValuePair<TKey,TValue>.

Exemplos

O exemplo de código a seguir mostra como enumerar as chaves e os valores em um dicionário, usando a KeyValuePair<TKey,TValue> estrutura.

Esse código faz parte de um exemplo maior fornecido para a 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

Comentários

Essa propriedade é somente leitura/somente.

Aplica-se a