Is there between DateTime in C# ? I know I can do simple check with if (a > date1 && a < date2) but I was trying to find Between meth
Why restrict to just dates, use the IComparable interface.
public static bool InclusiveBetween (this IComparable a, IComparable b, IComparable c)
{
return a.CompareTo(b) >= 0 && a.CompareTo(c) <= 0;
}
public static bool ExclusiveBetween (this IComparable a, IComparable b, IComparable c)
{
return a.CompareTo(b) > 0 && a.CompareTo(c) < 0;
}
public static bool SqlBetween (this IComparable a, IComparable b, IComparable c)
{
return a.InclusiveBetween(b, c);
}