DateTime - InRange

A T extension method that check if the value is between inclusively the minValue and maxValue.

Try it

public static void Main()
{
    DateTime searchDate = DateTime.Now;
	
	DateTime minDate = new DateTime(2018, 12, 25);
	
	DateTime maxDate = new DateTime(2019, 2, 28);

    // C# Extension Method: DateTime - InRange
	if(searchDate.InRange(minDate, maxDate))
	{
		Console.WriteLine("{0} is in range [{1} --- {2}]", searchDate, minDate, maxDate);
	}
	else
	{
		Console.WriteLine("{0} is not in range [{1} --- {2}]", searchDate, minDate, maxDate);
	}
}

View Source
using System;

public static partial class Extensions
{
    /// <summary>
    ///     A T extension method that check if the value is between inclusively the minValue and maxValue.
    /// </summary>
    /// <param name="this">The @this to act on.</param>
    /// <param name="minValue">The minimum value.</param>
    /// <param name="maxValue">The maximum value.</param>
    /// <returns>true if the value is between inclusively the minValue and maxValue, otherwise false.</returns>
    /// ###
    /// <typeparam name="T">Generic type parameter.</typeparam>
    public static bool InRange(this DateTime @this, DateTime minValue, DateTime maxValue)
    {
        return @this.CompareTo(minValue) >= 0 && @this.CompareTo(maxValue) <= 0;
    }
}