SortedDictionary<TKey,TValue>.Keys Eigenschap
Definitie
Belangrijk
Bepaalde informatie heeft betrekking op een voorlopige productversie die aanzienlijk kan worden gewijzigd voordat deze wordt uitgebracht. Microsoft biedt geen enkele expliciete of impliciete garanties met betrekking tot de informatie die hier wordt verstrekt.
Hiermee haalt u een verzameling op met de sleutels in de 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
Waarde van eigenschap
Een SortedDictionary<TKey,TValue>.KeyCollection met de sleutels in de SortedDictionary<TKey,TValue>.
Voorbeelden
In het volgende codevoorbeeld ziet u hoe u de sleutels in de woordenlijst opsommen met behulp van de Keys eigenschap en hoe u de sleutels en waarden in de woordenlijst opsommen.
Deze code maakt deel uit van een groter voorbeeld dat kan worden gecompileerd en uitgevoerd. Zie 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
Opmerkingen
De sleutels in de SortedDictionary<TKey,TValue>.KeyCollection eigenschap worden gesorteerd op basis van de Comparer eigenschap en bevinden zich in dezelfde volgorde als de bijbehorende waarden in de SortedDictionary<TKey,TValue>.ValueCollection geretourneerde Values eigenschap.
Het geretourneerde SortedDictionary<TKey,TValue>.KeyCollection is geen statische kopie. In plaats daarvan verwijst de SortedDictionary<TKey,TValue>.KeyCollection waarde terug naar de sleutels in het origineel SortedDictionary<TKey,TValue>. Daarom blijven wijzigingen in de wijzigingen in de SortedDictionary<TKey,TValue>SortedDictionary<TKey,TValue>.KeyCollection.
Het ophalen van de waarde van deze eigenschap is een O(1)-bewerking.