IsBetween
Checks whether the given integer value is between the start and end value.
Source
/// <summary>
/// Determines whether the specified value falls between start and end value. Check is done inclusive of start and end.
/// </summary>
/// <param name="value">The value.</param>
/// <param name="start">The start.</param>
/// <param name="end">The end.</param>
/// <returns>
/// <c>true</c> if the specified start is between; otherwise, <c>false</c>.
/// </returns>
public static bool IsBetween(this int value, int start, int end)
{
return Comparer<int>.Default.Compare(value, start) >= 0 && Comparer<int>.Default.Compare(value, end) <= 0;
}
Example
int value = 15;
return value.IsBetween(14, 16);