use*_*285 1 f# typechecking f#-interactive
我试图检查变量是否是某种类型,如下所示:
let s = "abc"
let isString = s :? string
Run Code Online (Sandbox Code Playgroud)
但在F#interactive中,我收到以下错误:
error FS0016: The type 'string' does not have any proper subtypes and cannot be used as the source of a type test or runtime coercion.
为什么会这样?我希望isString是一个bool.
因为你正在尝试使用密封型.
试试这个:
let s = box "abc"
let isString = s :? string
Run Code Online (Sandbox Code Playgroud)
使用密封类型执行此强制测试没有意义,因为它们不能具有任何子类型,这就是错误消息告诉您的内容.
归档时间: |
|
查看次数: |
573 次 |
最近记录: |