Between

public static bool Between<T>(this T me, T lower, T upper) where T : IComparable<T>
{
  return me.CompareTo(lower) >= 0 && me.CompareTo(upper) < 0;
}
Example:
if (someNumber.Between(3,7)) // Do stuff...

Description

Works on Comparables to check whether the checked value is between two other values. Check relaifciotn.net -> extension methods for more details.

Details

Double click on the code to select all.

 

;