'Between' Extension Method

by Donovan Olivier May 24, 2011 2:26PM

Check whether any IComparable<T> falls within a range.

public static bool Between<T>(this T item, T start, T end) where T : IComparable<T>
{
    return (item.CompareTo(start) >= 0 && item.CompareTo(end) <= 0);
}

Tags: ,

Blog

Comments are closed

The Perpetrator

perpetrator

Donovan Olivier

software developer, architect, husband, father, son, brother, uncle, nephew, sinistral, enquirer, skeptic, cynic, anarchist, contrarian, infidel, dissident, rebel, troublemaker, dissenter, renegade.

Noise

damn this winter appetite!
planetdonovan 1 day ago

@planetdonovan it seems to be the standard ratio!
marceldupreez 1 day ago

@marceldupreez cuz there's one in every carriage ;)
planetdonovan 1 day ago

RT @marclottering: Feel like getting stoned proper today. Anyone have a COSATU connection?
planetdonovan 2 days ago

fail of the day http://t.co/7l0RI9lr
planetdonovan 4 days ago

currently suffering from severe malbeertrition.
planetdonovan 7 days ago