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

Between

c# version of "Between" clause of sql query

Source

public static bool Between<T>(this T value, T from, T to) where T : IComparable<T>
{
    return value.CompareTo(from) >= 0 && value.CompareTo(to) <= 0;
}

Example

DateTime today = DateTime.Now;
var from = new DateTime(2012, 2, 1);
var to = new DateTime(2012, 12,20);

bool isBetween = today.Between(from, to);

Author: Raveendra sharma

Submitted on: 1 nov. 2012

Language: C#

Type: Type

Views: 10156