語言

KeyValuePair<TKey,TValue>.Key 屬性

定義

取得鍵值對中的金鑰。

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

屬性值

TKey

A TKey 是 的鍵 KeyValuePair<TKey,TValue>。

範例

以下程式碼範例說明如何使用結構在字典 KeyValuePair<TKey,TValue> 中枚舉鍵與值。

此程式碼是該類別更大 Dictionary<TKey,TValue> 範例的一部分。

// 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

備註

此屬性為僅讀。

適用於