Dictionary.Keys プロパティ
アセンブリ: mscorlib (mscorlib.dll 内)
構文
Dim instance As Dictionary(Of TKey, TValue) Dim value As KeyCollection value = instance.Keys
public KeyCollection Keys { get; }
public: property KeyCollection^ Keys { KeyCollection^ get (); }
/** @property */ public KeyCollection get_Keys ()
Dictionary 内のキーを格納している Dictionary.KeyCollection。
Dictionary.KeyCollection 内のキーの順序は指定されていませんが、関連付けられている値が、Values プロパティから返された Dictionary.ValueCollection 内で並べられている順序と同じです。
返される Dictionary.KeyCollection は静的なコピーではありません。代わりに、この Dictionary.KeyCollection は、元の Dictionary のキーを参照します。そのため、Dictionary に対する変更は、Dictionary.KeyCollection にも反映されます。
Keys プロパティを使用してディクショナリのキーを列挙する方法、およびディクショナリのキーおよび値を列挙する方法を次のコード例に示します。
このコードは、コンパイルして実行することのできる例の一部です。詳細については、Dictionary のトピックを参照してください。
' 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 <br /><span space="preserve">...</span><br /> ' 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
// 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); } <br /><span space="preserve">...</span><br /> // 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); }
Windows 98, Windows 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile for Pocket PC, Windows Mobile for Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
開発プラットフォームの中には、.NET Framework によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。
参照
Dictionary ジェネリック クラス
Dictionary メンバ
System.Collections.Generic 名前空間
Dictionary.KeyCollection
Values
- Dictionary.Keys プロパティのページへのリンク