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

定義

SortedDictionary<TKey,TValue> 内のキーを格納しているコレクションを取得します。

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

プロパティ値

SortedDictionary<TKey,TValue>.KeyCollection

SortedDictionary<TKey,TValue>.KeyCollection 内のキーを格納している SortedDictionary<TKey,TValue>

次のコード例は、プロパティを使用して Keys ディクショナリ内のキーを列挙する方法と、ディクショナリ内のキーと値を列挙する方法を示しています。

このコードは、コンパイルおよび実行できるより大きな例の一部です。 以下を参照してください。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

注釈

内のSortedDictionary<TKey,TValue>.KeyCollectionキーは、プロパティにComparer従って並べ替えられます。プロパティによってValues返される関連する値SortedDictionary<TKey,TValue>.ValueCollectionと同じ順序で並べ替えられます。

返されるSortedDictionary<TKey,TValue>.KeyCollectionコピーは静的コピーではありません。代わりに、元SortedDictionary<TKey,TValue>SortedDictionary<TKey,TValue>.KeyCollectionキーを参照します。 したがって、継続に対する SortedDictionary<TKey,TValue> 変更は、.に反映され SortedDictionary<TKey,TValue>.KeyCollection続けます。

このプロパティの値の取得は O(1) 操作です。

適用対象

こちらもご覧ください