Dictionary.Keys プロパティとは? わかりやすく解説

Weblio 辞書 > コンピュータ > .NET Framework クラス ライブラリ リファレンス > Dictionary.Keys プロパティの意味・解説 

Dictionary.Keys プロパティ

メモ : このプロパティは、.NET Framework version 2.0新しく追加されたものです。

Dictionary 内のキー格納しているコレクション取得します

名前空間: System.Collections.Generic
アセンブリ: mscorlib (mscorlib.dll 内)
構文構文

解説解説

Dictionary.KeyCollection 内のキー順序指定されていませんが、関連付けられている値が、Values プロパティから返された Dictionary.ValueCollection 内で並べられている順序と同じです。

返される Dictionary.KeyCollection静的コピーではありません。代わりに、この Dictionary.KeyCollection は、元の Dictionaryキー参照します。そのため、Dictionary対す変更は、Dictionary.KeyCollection にも反映されます。

このプロパティ値を取得することは、O(1) 操作なります

使用例使用例

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);
        }
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照



英和和英テキスト翻訳>> Weblio翻訳
英語⇒日本語日本語⇒英語
  

辞書ショートカット

すべての辞書の索引

「Dictionary.Keys プロパティ」の関連用語

Dictionary.Keys プロパティのお隣キーワード
検索ランキング

   

英語⇒日本語
日本語⇒英語
   



Dictionary.Keys プロパティのページの著作権
Weblio 辞書 情報提供元は 参加元一覧 にて確認できます。

   
日本マイクロソフト株式会社日本マイクロソフト株式会社
© 2024 Microsoft.All rights reserved.

©2024 GRAS Group, Inc.RSS