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
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();
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
備註
此屬性是唯讀的。