共用方式為


IDictionary<TKey,TValue>.Keys 屬性

定義

取得 ICollection<T>,包含 IDictionary<TKey,TValue> 的索引鍵。

public:
 property System::Collections::Generic::ICollection<TKey> ^ Keys { System::Collections::Generic::ICollection<TKey> ^ get(); };
public System.Collections.Generic.ICollection<TKey> Keys { get; }
member this.Keys : System.Collections.Generic.ICollection<'Key>
Public ReadOnly Property Keys As ICollection(Of TKey)

屬性值

ICollection<TKey>

ICollection<T>,包含實作 IDictionary<TKey,TValue> 之物件的索引鍵。

範例

下列程式代碼範例示範如何使用 屬性單獨 Keys 列舉索引鍵。

此程式代碼是可編譯和執行之較大範例的一部分。 請參閱 System.Collections.Generic.IDictionary<TKey,TValue>

// To get the keys alone, use the Keys property.
icoll = openWith->Keys;

// The elements of the ValueCollection are strongly typed
// with the type that was specified for dictionary values.
Console::WriteLine();
for each( String^ s in icoll )
{
    Console::WriteLine("Key = {0}", s);
}
// To get the keys alone, use the Keys property.
icoll = openWith.Keys;

// The elements of the ValueCollection are strongly typed
// with the type that was specified for dictionary values.
Console.WriteLine();
foreach( string s in icoll )
{
    Console.WriteLine("Key = {0}", s);
}
' To get the keys alone, use the Keys property.
icoll = openWith.Keys

' The elements of the ValueCollection are strongly typed
' with the type that was specified for dictionary values.
Console.WriteLine()
For Each s As String In  icoll
    Console.WriteLine("Key = {0}", s)
Next s

備註

未指定所ICollection<T>傳回之索引鍵的順序,但保證其順序與 屬性所Values傳回之 中的ICollection<T>對應值的順序相同。

適用於

另請參閱