是否有一个&QUOT ...之间QUOT;在C#中的功能? [英] Is there a "between" function in C#?

查看:134
本文介绍了是否有一个&QUOT ...之间QUOT;在C#中的功能?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

谷歌不明白之间是我找的函数的名称,并且没有返回相关的。

Google doesn't understand that "between" is the name of the function I'm looking for and returns nothing relevant.

例如:我要检查,如果5只在一个操作是0到10之间。

Ex: I want to check if 5 is between 0 and 10 in only one operation

推荐答案

没有,但你可以编写自己的:

No, but you can write your own:

public static bool Between(this int num, int lower, int upper, bool inclusive = false)
{
    return inclusive
        ? lower <= num && num <= upper
        : lower < num && num < upper;
}

这篇关于是否有一个&QUOT ...之间QUOT;在C#中的功能?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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