KeyValuePair<TKey,TValue>.Key 屬性
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
取得鍵值對中的金鑰。
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
備註
此屬性為僅讀。