Share via


SortedList<TKey,TValue>.Keys Özellik

Tanım

içindeki anahtarları SortedList<TKey,TValue>içeren bir koleksiyonu sıralı olarak alır.

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

Özellik Değeri

IList<TKey>

IList<T> içindeki SortedList<TKey,TValue>anahtarları içeren bir.

Örnekler

Aşağıdaki kod örneği, özelliğini kullanarak Keys sıralanmış listedeki anahtarların nasıl numaralandırılıp sıralanmış listedeki anahtarların ve değerlerin nasıl numaralandırılıp listelendirilme şeklini gösterir.

Örnekte ayrıca anahtarların Keys verimli bir şekilde dizine alınması için özelliğinin nasıl kullanılacağı gösterilmektedir.

Bu kod, derlenip yürütülebilen daha büyük bir örneğin parçasıdır. Bkz. SortedList<TKey,TValue>.

// To get the keys alone, use the Keys property.
IList<String^>^ ilistKeys = openWith->Keys;

// The elements of the list are strongly typed with the
// type that was specified for the SortedList keys.
Console::WriteLine();
for each( String^ s in ilistKeys )
{
    Console::WriteLine("Key = {0}", s);
}

// The Keys property is an efficient way to retrieve
// keys by index.
Console::WriteLine("\nIndexed retrieval using the Keys " +
    "property: Keys[2] = {0}", openWith->Keys[2]);
// To get the keys alone, use the Keys property.
IList<string> ilistKeys = openWith.Keys;

// The elements of the list are strongly typed with the
// type that was specified for the SortedList keys.
Console.WriteLine();
foreach( string s in ilistKeys )
{
    Console.WriteLine("Key = {0}", s);
}

// The Keys property is an efficient way to retrieve
// keys by index.
Console.WriteLine("\nIndexed retrieval using the Keys " +
    "property: Keys[2] = {0}", openWith.Keys[2]);
' To get the keys alone, use the Keys property.
Dim ilistKeys As IList(Of String) = openWith.Keys

' The elements of the list are strongly typed with the
' type that was specified for the SortedList keys.
Console.WriteLine()
For Each s As String In ilistKeys 
    Console.WriteLine("Key = {0}", s)
Next s

' The Keys property is an efficient way to retrieve
' keys by index.
Console.WriteLine(vbLf & "Indexed retrieval using the " & _
    "Keys property: Keys(2) = {0}", openWith.Keys(2))
// To get the keys alone, use the Keys property.
let ilistKeys = openWith.Keys;

// The elements of the list are strongly typed with the
// type that was specified for the SortedList keys.
Console.WriteLine()
for s in ilistKeys do
    printfn $"Key = {s}"

// The Keys property is an efficient way to retrieve
// keys by index.
printf "\nIndexed retrieval using the Keys "
printfn $"property: Keys[2] = {openWith.Keys[2]}"
// When you use foreach to enumerate list elements,
// the elements are retrieved as KeyValuePair objects.
Console::WriteLine();
for each( KeyValuePair<String^, String^> kvp in openWith )
{
    Console::WriteLine("Key = {0}, Value = {1}",
        kvp.Key, kvp.Value);
}
// When you use foreach to enumerate list 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 list 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
// When you use foreach to enumerate list elements,
// the elements are retrieved as KeyValuePair objects.
Console.WriteLine()
for kvp in openWith do
    printfn $"Key = {kvp.Key}, Value = {kvp.Value}"

Açıklamalar

içindeki IList<T> anahtarların sırası, içindeki sırayla SortedList<TKey,TValue>aynıdır.

Döndürülen IList<T> bir statik kopya değildir; bunun yerine, IList<T> özgün SortedList<TKey,TValue>içindeki anahtarlara başvurur. Bu nedenle, dosyasındaki SortedList<TKey,TValue> değişiklikler öğesine IList<T>yansıtılmaya devam edilir.

özelliği tarafından Keys döndürülen koleksiyon, anahtarları dizine göre almak için verimli bir yol sağlar. Özelliğe erişildiğinde listeyi yeniden oluşturmak gerekmez, çünkü liste yalnızca iç anahtar dizisi için bir sarmalayıcıdır. Aşağıdaki kod, dize anahtarları içeren sıralanmış bir öğe listesinden anahtarların dizine alınan alınması için özelliğinin kullanımını Keys gösterir:

String^ v = mySortedList->Values[3];
string v = mySortedList.Values[3];
Dim v As String = mySortedList.Values(3)
let v = mySortedList.Values[3]

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

Şunlara uygulanır

Ayrıca bkz.