F# 相当于 C# 中的 `is` 关键字吗? [英] F# equivalent of `is` keyword in C#?

查看:31
本文介绍了F# 相当于 C# 中的 `is` 关键字吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的第一个 F# 日.如果我有这个:

let cat = Animal()

现在如何在后期检查cat is Animal?

在 C# 中

bool b = 猫是动物;

在 F# 中?

解决方案

@ildjarn 在这里值得称赞首先回答,但我在这里提交答案以便它被接受.>

与 C# is 关键字等效的 F# 关键字是 :?.例如:

let cat = Animal()如果猫:?动物然后printfn "猫是一种动物."别的printfn "猫不是动物."

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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆