在C#我可以这样做:
var castValue = inputValue as Type1
Run Code Online (Sandbox Code Playgroud)
在F#中,我可以这样做:
let staticValue = inputValue :> Type1
let dynamicValue = inputValue :?> Type1
Run Code Online (Sandbox Code Playgroud)
但它们都不等同于C#的关键字as.
我想我需要为F#中的等价物做一个匹配表达式
match inputValue with
| :? Type1 as type1Value -> type1Value
| _ -> null
Run Code Online (Sandbox Code Playgroud)
它是否正确?
我的第一个F#日.如果我有这个:
let cat = Animal()
Run Code Online (Sandbox Code Playgroud)
现在我如何在以后检查cat is Animal?
在C#中
bool b = cat is Animal;
Run Code Online (Sandbox Code Playgroud)
在F#?
我需要match用来检查值是字符串数组还是字符串.我尝试了一些徒劳的事情
| :? string[] -> ..
| :? string -> ..
| :? array<string[]> -> ..
Run Code Online (Sandbox Code Playgroud)
但是保留.
有帮助吗?