Поделиться через


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();
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> объекте не определен, но он гарантированно совпадает с соответствующими значениями в ICollection<T> возвращаемом свойстве Values .

Применяется к

См. также раздел