Dictionary<TKey,TValue>.Keys プロパティ
定義
重要
一部の情報は、リリース前に大きく変更される可能性があるプレリリースされた製品に関するものです。 Microsoft は、ここに記載されている情報について、明示または黙示を問わず、一切保証しません。
Dictionary<TKey,TValue> 内のキーを格納しているコレクションを取得します。
public:
property System::Collections::Generic::Dictionary<TKey, TValue>::KeyCollection ^ Keys { System::Collections::Generic::Dictionary<TKey, TValue>::KeyCollection ^ get(); };
public System.Collections.Generic.Dictionary<TKey,TValue>.KeyCollection Keys { get; }
member this.Keys : System.Collections.Generic.Dictionary<'Key, 'Value>.KeyCollection
Public ReadOnly Property Keys As Dictionary(Of TKey, TValue).KeyCollection
プロパティ値
Dictionary<TKey,TValue>.KeyCollection 内のキーを格納している Dictionary<TKey,TValue>。
例
次のコード例は、プロパティを使用して Keys ディクショナリ内のキーを列挙する方法と、ディクショナリ内のキーと値を列挙する方法を示しています。
このコードは、コンパイルおよび実行できるより大きな例の一部です (openWith
この例で使用されるディクショナリの名前です)。 以下を参照してください。Dictionary<TKey,TValue>
// To get the keys alone, use the Keys property.
Dictionary<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();
for each( String^ s in keyColl )
{
Console::WriteLine("Key = {0}", s);
}
// To get the keys alone, use the Keys property.
Dictionary<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 _
Dictionary(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();
for each( 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();
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
注釈
内のキーDictionary<TKey,TValue>.KeyCollectionの順序は指定されていませんが、プロパティによってValues返される関連する値Dictionary<TKey,TValue>.ValueCollectionと同じ順序です。
返されるDictionary<TKey,TValue>.KeyCollectionコピーは静的コピーではありません。代わりに、元Dictionary<TKey,TValue>のDictionary<TKey,TValue>.KeyCollectionキーを参照します。 したがって、変更が Dictionary<TKey,TValue> 継続 Dictionary<TKey,TValue>.KeyCollectionされ、.
このプロパティの値の取得は O(1) 操作です。