Aracılığıyla paylaş


SortedDictionary<TKey,TValue>.Keys Özellik

Tanım

içindeki SortedDictionary<TKey,TValue>anahtarları içeren bir koleksiyon alır.

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

Özellik Değeri

SortedDictionary<TKey,TValue>.KeyCollection içindeki SortedDictionary<TKey,TValue>anahtarları içeren bir .

Örnekler

Aşağıdaki kod örneği, özelliğini kullanarak Keys sözlükteki anahtarların nasıl numaralandırılıp sözlükteki anahtarların ve değerlerin numaralandırılıp numaralandırılamını gösterir.

Bu kod, derlenip yürütülebilen daha büyük bir örneğin parçasıdır. Bkz. 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

Açıklamalar

içindeki SortedDictionary<TKey,TValue>.KeyCollection anahtarlar özelliğine Comparer göre sıralanır ve özelliği tarafından Values döndürülen içindeki ilişkili değerlerle SortedDictionary<TKey,TValue>.ValueCollection aynı sıradadır.

Döndürülen SortedDictionary<TKey,TValue>.KeyCollection bir statik kopya değildir; bunun yerine, SortedDictionary<TKey,TValue>.KeyCollection özgün SortedDictionary<TKey,TValue>içindeki anahtarlara başvurur. Bu nedenle, dosyasında yapılan SortedDictionary<TKey,TValue> değişiklikler öğesine SortedDictionary<TKey,TValue>.KeyCollectionyansıtılmaya devam edilir.

Bu özelliğin değerini almak bir O(1) işlemidir.

Şunlara uygulanır

Ayrıca bkz.