Dictionary<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 Dictionary<TKey,TValue>.
public:
property System::Collections::Generic::Dictionary<TKey, TValue>::KeyCollection ^ Keys { System::Collections::Generic::Dictionary<TKey, TValue>::KeyCollection ^ get(); };
public System.Collections.Generic.Dictionary<TKey,TValue>.KeyCollection Keys { get; }
member this.Keys : System.Collections.Generic.Dictionary<'Key, 'Value>.KeyCollection
Public ReadOnly Property Keys As Dictionary(Of TKey, TValue).KeyCollection
Waarde van eigenschap
Een Dictionary<TKey,TValue>.KeyCollection met de sleutels in de Dictionary<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 (openWith is de naam van de woordenlijst die in dit voorbeeld wordt gebruikt). Zie Dictionary<TKey,TValue>.
// To get the keys alone, use the Keys property.
Dictionary<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.
let keyColl = openWith.Keys
// The elements of the KeyCollection are strongly typed
// with the type that was specified for dictionary keys.
printfn ""
for s in keyColl do
printfn $"Key = {s}"
' To get the keys alone, use the Keys property.
Dim keyColl As _
Dictionary(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.
printfn ""
for kvp in openWith do
printfn $"Key = {kvp.Key}, Value = {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 volgorde van de sleutels in de Dictionary<TKey,TValue>.KeyCollection sleutel is niet opgegeven, maar het is dezelfde volgorde als de bijbehorende waarden in de Dictionary<TKey,TValue>.ValueCollection geretourneerde Values eigenschap.
Het geretourneerde Dictionary<TKey,TValue>.KeyCollection is geen statische kopie. In plaats daarvan verwijst de Dictionary<TKey,TValue>.KeyCollection waarde terug naar de sleutels in het origineel Dictionary<TKey,TValue>. Daarom blijven wijzigingen in de wijzigingen in de Dictionary<TKey,TValue>Dictionary<TKey,TValue>.KeyCollection.
Het ophalen van de waarde van deze eigenschap is een O(1)-bewerking.