F#等同于C#中的is关键字? [英] F# equivalent of `is` keyword in C#?
本文介绍了F#等同于C#中的is关键字?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在F#的第一天.如果我有这个话:
let cat = Animal()
现在我该如何在以后检查cat
is
Animal
?
在C#中
bool b = cat is Animal;
在F#中?
解决方案
@ildjarn在此功劳第一,但我在这里提交了答案,因此可以接受. >
C#is
关键字的F#等效项是:?
.例如:
let cat = Animal()
if cat :? Animal then
printfn "cat is an animal."
else
printfn "cat is not an animal."
My first F# day. If I have this:
let cat = Animal()
Now how do I check at later stage if cat
is
Animal
?
In C#
bool b = cat is Animal;
In F#?
解决方案
@ildjarn deserves the credit here for answering first, but I'm submitting the answer here so it can be accepted.
The F# equivalent of the C# is
keyword is :?
. For example:
let cat = Animal()
if cat :? Animal then
printfn "cat is an animal."
else
printfn "cat is not an animal."
这篇关于F#等同于C#中的is关键字?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文