Double - Between
A T extension method that check if the value is between (exclusif) the minValue and maxValue.
public static void Main() { double searchVal = 7.64; double minVal = 7.03; double maxVal = 32.7865; // C# Extension Method: Double - Between if(searchVal.Between(minVal, maxVal)) { Console.WriteLine("{0} is between {1} and {2}", searchVal, minVal, maxVal); } else { Console.WriteLine("{0} is not between {1} and {2}", searchVal, minVal, maxVal); } }
View Source
using System; public static partial class Extensions { /// <summary> /// A T extension method that check if the value is between (exclusif) the minValue and maxValue. /// </summary> /// <param name="this">The @this to act on.</param> /// <param name="minValue">The minimum value.</param> /// <param name="maxValue">The maximum value.</param> /// <returns>true if the value is between the minValue and maxValue, otherwise false.</returns> /// ### /// <typeparam name="T">Generic type parameter.</typeparam> public static bool Between(this Double @this, Double minValue, Double maxValue) { return minValue.CompareTo(@this) == -1 && @this.CompareTo(maxValue) == -1; } }