在C#中我可以这样做:C#和F#铸 - 特别是 '为' 关键字
var castValue = inputValue as Type1
在F#中,我可以这样做:
let staticValue = inputValue :> Type1
let dynamicValue = inputValue :?> Type1
但它们都不是的等效C#作为
我想我需要在F#相当于做一个匹配表达式
match inputValue with
| :? Type1 as type1Value -> type1Value
| _ -> null
这是正确的吗?
这工作如果类型是静态的。任何想法如果类型是在运行时定义的怎么办?我正在寻找一个F#相当于http://stackoverflow.com/a/19068042/23059。 – 2015-12-28 03:12:19