ExtensionMethod.NET Home of 877 C#, Visual Basic, F# and Javascript extension methods


Checks whether the given integer value is between the start and end value.


/// <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;


int value = 15;
return value.IsBetween(14, 16);

Author: Sheraz Naseeb

Submitted on: 15 nov. 2016

Language: C#

Type: Integer

Views: 4578