SortedDictionary<TKey,TValue>.Keys Egenskap
Definition
Viktigt
En del information gäller för förhandsversionen av en produkt och kan komma att ändras avsevärt innan produkten blir allmänt tillgänglig. Microsoft lämnar inga garantier, uttryckliga eller underförstådda, avseende informationen som visas här.
Hämtar en samling som innehåller nycklarna i 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
Egenskapsvärde
En SortedDictionary<TKey,TValue>.KeyCollection som innehåller nycklarna i SortedDictionary<TKey,TValue>.
Exempel
I följande kodexempel visas hur du räknar upp nycklarna i ordlistan med hjälp av Keys egenskapen och hur du räknar upp nycklar och värden i ordlistan.
Den här koden är en del av ett större exempel som kan kompileras och köras. Se även SortedDictionary<TKey,TValue>.
// 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
Kommentarer
Nycklarna i SortedDictionary<TKey,TValue>.KeyCollection sorteras enligt Comparer egenskapen och är i samma ordning som de associerade värdena i den SortedDictionary<TKey,TValue>.ValueCollection returnerade Values egenskapen.
Den returnerade SortedDictionary<TKey,TValue>.KeyCollection är inte en statisk kopia. I stället SortedDictionary<TKey,TValue>.KeyCollection refererar den tillbaka till nycklarna i den ursprungliga SortedDictionary<TKey,TValue>. Därför fortsätter ändringarna att SortedDictionary<TKey,TValue> återspeglas i SortedDictionary<TKey,TValue>.KeyCollection.
Att hämta värdet för den här egenskapen är en O(1)-åtgärd.