F# equivalent of `is` keyword in C#?

前端 未结 3 1592
心在旅途
心在旅途 2020-12-10 12:18

My first F# day. If I have this:

let cat = Animal()

Now how do I check at later stage if cat is Animal

3条回答
  •  暖寄归人
    2020-12-10 12:49

    @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."
    

提交回复
热议问题