ExtraTopLevelOperators.dict<'Key,'Value> 函式 (F#)
更新:2010 年 5 月
從索引鍵/值組序列,建置唯讀查閱資料表。 使用泛形雜湊和相等,檢索索引鍵物件。
命名空間/模組路徑: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 7、Windows Vista SP2、Windows XP SP3、Windows XP x64 SP2、Windows Server 2008 R2、Windows Server 2008 SP2、Windows Server 2003 SP2
版本資訊
F# 執行階段
支援版本:2.0、4.0
Silverlight
支援版本:3
請參閱
參考
Core.ExtraTopLevelOperators 模組 (F#)
Microsoft.FSharp.Core 命名空間 (F#)
變更記錄
日期 |
History |
原因 |
---|---|---|
2010 年 5 月 |
加入程式碼範例。 |
資訊加強。 |