SortedList<TKey,TValue>.Keys 속성

정의

SortedList<TKey,TValue>에 있는 키가 들어있는 컬렉션을 정렬 순서대로 가져옵니다.

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)

속성 값

IList<TKey>

IList<T>의 키를 포함하는 SortedList<TKey,TValue>입니다.

예제

다음 코드 예제에서는 속성을 사용 하 여 Keys 정렬 된 목록에서 키를 열거 하는 방법 및 정렬 된 목록에서 키와 값을 열거 하는 방법을 보여 줌

이 예제에서는 키를 효율적으로 인덱싱한 검색을 위해 속성을 사용하는 Keys 방법도 보여 집니다.

이 코드는 컴파일 및 실행할 수 있는 더 큰 예제의 일부입니다. 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}"

설명

의 키 IList<T> 순서는 의 순서 SortedList<TKey,TValue>와 동일합니다.

반환 IList<T> 된 는 정적 복사본이 아니며, 대신 는 IList<T> 원래 SortedList<TKey,TValue>의 키를 다시 참조합니다. 따라서 에 대한 SortedList<TKey,TValue> 변경 내용은 에 계속 반영됩니다 IList<T>.

속성에서 반환된 Keys 컬렉션은 인덱스별로 키를 검색하는 효율적인 방법을 제공합니다. 속성에 액세스할 때 목록을 다시 생성할 필요는 없습니다. 목록이 키의 내부 배열에 대한 래퍼이기 때문입니다. 다음 코드에서는 문자열 키가 있는 정렬된 요소 목록에서 인덱싱된 키 검색에 속성을 사용하는 Keys 방법을 보여 있습니다.

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

이 속성 값을 검색하는 것은 O(1) 연산입니다.

적용 대상

추가 정보