SortedDictionary<TKey,TValue>.Keys Właściwość

Definicja

Pobiera kolekcję zawierającą klucze w obiekcie SortedDictionary<TKey,TValue>.

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

Wartość właściwości

Element SortedDictionary<TKey,TValue>.KeyCollection zawierający klucze w elemecie SortedDictionary<TKey,TValue>.

Przykłady

Poniższy przykład kodu przedstawia sposób wyliczania kluczy w słowniku przy użyciu Keys właściwości oraz wyliczania kluczy i wartości w słowniku.

Ten kod jest częścią większego przykładu, który można skompilować i wykonać. Zobacz: .

// To get the keys alone, use the Keys property.
SortedDictionary<string, string>.KeyCollection keyColl =
    openWith.Keys;

// The elements of the KeyCollection are strongly typed
// with the type that was specified for dictionary keys.
Console.WriteLine();
foreach( string s in keyColl )
{
    Console.WriteLine("Key = {0}", s);
}
' To get the keys alone, use the Keys property.
Dim keyColl _
    As SortedDictionary(Of String, String).KeyCollection = _
    openWith.Keys

' The elements of the KeyCollection are strongly typed
' with the type that was specified for dictionary keys.
Console.WriteLine()
For Each s As String In keyColl 
    Console.WriteLine("Key = {0}", s)
Next s
// 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

Uwagi

Klucze w obiekcie SortedDictionary<TKey,TValue>.KeyCollection są sortowane zgodnie z Comparer właściwością i są w tej samej kolejności co skojarzone wartości w zwróconej SortedDictionary<TKey,TValue>.ValueCollection przez Values właściwość.

Zwrócony SortedDictionary<TKey,TValue>.KeyCollection element nie jest kopią statyczną. Zamiast tego SortedDictionary<TKey,TValue>.KeyCollection odwołuje się do kluczy w oryginalnym SortedDictionary<TKey,TValue>obiekcie . W związku z tym zmiany w SortedDictionary<TKey,TValue> dalszym ciągu zostaną odzwierciedlone w obiekcie SortedDictionary<TKey,TValue>.KeyCollection.

Pobieranie wartości tej właściwości jest operacją O(1).

Dotyczy

Zobacz też