如何确定对象是否是F#中的某种类型

phi*_*hil 15 f#

在C#中我可以使用关键字'is'

if (variable is string)
{
}
Run Code Online (Sandbox Code Playgroud)

怎么在f#中完成

Cᴏʀ*_*ᴏʀʏ 25

尝试

if (variable :? string) ...
Run Code Online (Sandbox Code Playgroud)

要么

let x = variable :? string
Run Code Online (Sandbox Code Playgroud)

  • C# 的“as”运算符等效项怎么样? (2认同)
  • 请参阅http://stackoverflow.com/questions/2361851/c-sharp-and-f-casting-specially-the-as-keyword @Andrii (2认同)