Map.TryFind<'Key,'Value> 方法 (F#)
更新:2010 年 8 月
在對應中查詢項目,如果該項目位於對應的網域中則傳回 Some 這個值,否則傳回 None。
命名空間/模組路徑: Microsoft.FSharp.Collections
組件:FSharp.Core (在 FSharp.Core.dll 中)
// Signature:
member this.TryFind : 'Key -> 'Value option (requires comparison)
// Usage:
map.TryFind (key)
參數
key
型別:'Key輸入索引鍵。
傳回值
對應的值或者 None如果機碼不在 對應中。
範例
下列程式碼將示範如何使用 TryFind 方法。
let map1 = [ for i in 1 .. 100 -> (i, i*i) ] |> Map.ofList
let result = map1.TryFind 50
match result with
| Some x -> printfn "Found %d." x
| None -> printfn "Did not find the specified 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
請參閱
參考
Collections.Map<'Key,'Value> 類別 (F#)
Microsoft.FSharp.Collections 命名空間 (F#)
變更記錄
日期 |
History |
原因 |
---|---|---|
2010 年 8 月 |
加入程式碼範例。 |
資訊加強。 |