F#:检查值是字符串数组,字符串数组还是字符串
问题描述:
我需要使用match
来检查值是字符串数组还是字符串.我尝试了一些徒劳的事情
I need use match
to check if a value is an array of strings or a string. I've tried something in the vain of
| :? string[] -> ..
| :? string -> ..
| :? array<string[]> -> ..
但无济于事.
有帮助吗?
答
您需要稍微修改语法,但是您几乎是正确的
You need to modify the syntax slightly, but you were almost correct
let fn (arg:obj) =
match arg with
| :? string as str -> printfn "string"
| :? (string[]) as arr -> printfn "string array"