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

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

注解

此属性为只读/只读。

适用于