SortedDictionary<TKey,TValue>.Keys プロパティ
定義
重要
一部の情報は、リリース前に大きく変更される可能性があるプレリリースされた製品に関するものです。 Microsoft は、ここに記載されている情報について、明示または黙示を問わず、一切保証しません。
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>内のキーを含むSortedDictionary<TKey,TValue>.KeyCollection。
例
次のコード例は、 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>.KeyCollection は元の SortedDictionary<TKey,TValue>のキーを参照します。 そのため、 SortedDictionary<TKey,TValue> への変更は引き続き SortedDictionary<TKey,TValue>.KeyCollectionに反映されます。
このプロパティの値の取得は O(1) 操作です。