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

Between

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

Source

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...

Author: Frank Quednau

Submitted on: 5 mrt. 2008

Language: C#

Type: System.IComparable<T>

Views: 4854