SortedList<TKey,TValue>.Keys 속성
정의
중요
일부 정보는 릴리스되기 전에 상당 부분 수정될 수 있는 시험판 제품과 관련이 있습니다. Microsoft는 여기에 제공된 정보에 대해 어떠한 명시적이거나 묵시적인 보증도 하지 않습니다.
정렬된 순서대로 키를 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<T> 에 있는 키를 포함하는 A.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();
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();
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];
Dim v As String = mySortedList.Values(3)
let v = mySortedList.Values[3]
이 속성의 값을 검색하는 것은 O(1) 작업입니다.