SortedList<TKey,TValue>.Keys プロパティ

定義

並べ替えられた順序で、SortedList<TKey,TValue> 内のキーを含むコレクションを取得します。Gets a collection containing the keys in the SortedList<TKey,TValue>, in sorted order.

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>A IList<T> containing the keys in the SortedList<TKey,TValue>.

次のコード例は、 Keysプロパティを使用して並べ替えられたリスト内のキーを列挙する方法と、並べ替えられたリスト内のキーと値を列挙する方法を示しています。The following code example shows how to enumerate the keys in the sorted list using the Keys property, and how to enumerate the keys and values in the sorted list.

また、この例では、プロパティKeysを使用して、キーのインデックスを効率的に取得する方法も示しています。The example also shows how to use the Keys property for efficient indexed retrieval of keys.

このコードは、コンパイルして実行できる大きな例の一部です。This code is part of a larger example that can be compiled and executed. 以下を参照してください。SortedList<TKey,TValue>See 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))
// 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

注釈

IList<T>のキーの順序は、 SortedList<TKey,TValue>の順序と同じです。The order of the keys in the IList<T> is the same as the order in the SortedList<TKey,TValue>.

返さIList<T>れるは静的なコピーではなく、 IList<T>は元SortedList<TKey,TValue>ののキーを参照します。The returned IList<T> is not a static copy; instead, the IList<T> refers back to the keys in the original SortedList<TKey,TValue>. したがって、へSortedList<TKey,TValue>の変更は、 IList<T>引き続きに反映されます。Therefore, changes to the SortedList<TKey,TValue> continue to be reflected in the IList<T>.

Keysプロパティによって返されるコレクションは、インデックスによってキーを取得する効率的な方法を提供します。The collection returned by the Keys property provides an efficient way to retrieve keys by index. リストはキーの内部配列のラッパーであるため、プロパティにアクセスしたときにリストを再生成する必要はありません。It is not necessary to regenerate the list when the property is accessed, because the list is just a wrapper for the internal array of keys. 次のコードは、文字列キーをKeys使用して、並べ替えられた要素のリストからキーをインデックス付きで取得するためのプロパティの使用方法を示しています。The following code shows the use of the Keys property for indexed retrieval of keys from a sorted list of elements with string keys:

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

このプロパティ値を取得することは、O(1) 操作になります。Retrieving the value of this property is an O(1) operation.

適用対象

こちらもご覧ください