在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