ExtraTopLevelOperators.dict<'Key,'Value> 関数 (F#)

キーと値のペアのシーケンスから読み取り専用のルックアップ テーブルを構築します。キー オブジェクトには、汎用ハッシュと等値を使用してインデックスが付けられます。

名前空間/モジュール パス: Microsoft.FSharp.Core.ExtraTopLevelOperators

アセンブリ: FSharp.Core (FSharp.Core.dll)

// Signature:
dict : seq<'Key * 'Value> -> IDictionary<'Key,'Value> (requires equality)

// Usage:
dict keyValuePairs

パラメーター

  • keyValuePairs
    型: seq<'Key * 'Value>

戻り値

指定されたコレクションを表す、IDictionary<TKey, TValue> を実装したオブジェクト。

解説

この関数は、コンパイルされたアセンブリでは CreateDictionary という名前です。F# 以外の言語から、またはリフレクションを使用してこの関数にアクセスする場合は、この名前を使用します。

使用例

dict 関数を使用するコード例を次に示します。

open System
open System.Collections.Generic

let seq1 = seq { for i in 1..10 -> i, i*i }
let dictionary1 = dict seq1
if dictionary1.IsReadOnly then
    Console.WriteLine("The dictionary is read only.")
// The type is a read only IDictionary.
// If you try to add or remove elements,
// NotSupportedException is generated, as in the following line:
//dictionary1.Add(new KeyValuePair<int, int>(0, 0))
// You can use read-only methods as in the following lines.
if dictionary1.ContainsKey(5) then
    Console.WriteLine("Value for key 5: {0}", dictionary1.Item(5))
for elem in dictionary1 do
   Console.WriteLine("Key: {0} Value: {1}", elem.Key, elem.Value) 

出力は次のとおりです。

  
  

プラットフォーム

Windows 8、Windows 7、Windows Server 2012 で Windows Server 2008 R2

バージョン情報

F# コア ライブラリのバージョン

サポート: ポータブル 2.0、4.0

参照

関連項目

Core.ExtraTopLevelOperators モジュール (F#)

Microsoft.FSharp.Core 名前空間 (F#)