F#: check if a value is an array of strings, an array of arrays of string or a string

后端 未结 1 1990
不知归路
不知归路 2021-01-19 16:35

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         


        
相关标签:
1条回答
  • 2021-01-19 16:53

    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"
    
    0 讨论(0)
提交回复
热议问题