我写了这段代码
type Test =
| Age of int
| Name of string;;
let x = Age(10);;
if (x.GetType() = typeof<Test>) then printfn "true" else printfn "false";;
代码打印错误。但这让我感到困惑,因为不是类型测试的年龄吗?
另外,有没有更好的方法来比较 F# 中的类型.GetType() = typeof<>
很长。我试过:?
了,但我认为这是用于类型转换而不是比较类型。