Determine if a number falls within a specified set of ranges

后端 未结 8 1446
耶瑟儿~
耶瑟儿~ 2021-02-02 13:45

I\'m looking for a fluent way of determining if a number falls within a specified set of ranges. My current code looks something like this:

int x = 500; // Could         


        
8条回答
  •  被撕碎了的回忆
    2021-02-02 14:03

    LINQ approach :

    Add the reference:

    using System.Linq;
    
            /// 
            /// Test to see if value is in specified range.
            /// 
            /// int
            /// int
            /// int
            /// bool
            public static bool CheckValueInRange(int aStart, int aEnd, int aValueToTest)
            {
                // check value in range...
                bool ValueInRange = Enumerable.Range(aStart, aEnd).Contains(aValueToTest);
                // return value...
                return ValueInRange;
            }
    

提交回复
热议问题