我在F#中的Dictionary上使用TryGetValue并返回一个对象 bool * Dictionary<int, object>
我一直在谷歌搜索几个小时,但如何访问此对象的bool组件,以便我可以检查它是否已返回值?
请救我免邮...
Foo*_*ole 20
有几个选择.
最简单的可能是:
let found, value = dict.TryGetValue key
Run Code Online (Sandbox Code Playgroud)
或者:
let pair = dict.TryGetValue key
let found = fst pair
let value = snd pair
Run Code Online (Sandbox Code Playgroud)
最常见的模式是:
match dict.TryGetValue key with
| true, value -> (* do something with value *)
| _ -> (* handle the case of value not found *)
Run Code Online (Sandbox Code Playgroud)