Class IComparableExtensions

Namespace
Wolfgang.Extensions.IComparable
Assembly
Wolfgang.Extensions.IComparable.dll

A collection of extension methods for types that implement IComparable<T>.

public static class IComparableExtensions
Inheritance
IComparableExtensions
Inherited Members

Methods

IsBetween<T>(T, T, T)

Determines if the specified value is strictly greater than the lowerBound and strictly less than the upperBound.

public static bool IsBetween<T>(this T value, T lowerBound, T upperBound) where T : IComparable<T>

Parameters

value T

The value to compare.

lowerBound T

The exclusive lower bound of the range.

upperBound T

The exclusive upper bound of the range.

Returns

bool

true if value is greater than lowerBound and less than upperBound; otherwise, false.

Type Parameters

T

The type of the values being compared.

Examples

using Wolfgang.Extensions.IComparable;

int score = 75;
bool inOpenRange = score.IsBetween(70, 80);   // true  — 70 < 75 < 80
bool atLower     = 70.IsBetween(70, 80);      // false — 70 is NOT > 70
bool atUpper     = 80.IsBetween(70, 80);      // false — 80 is NOT < 80

Exceptions

ArgumentNullException

value is null.

IsInRange<T>(T, T, T)

Determines if the specified value is greater than or equal to the lowerBound and less than or equal to the upperBound.

public static bool IsInRange<T>(this T value, T lowerBound, T upperBound) where T : IComparable<T>

Parameters

value T

The value to compare.

lowerBound T

The inclusive lower bound of the range.

upperBound T

The inclusive upper bound of the range.

Returns

bool

true if value is greater than or equal to lowerBound and less than or equal to upperBound; otherwise, false.

Type Parameters

T

The type of the values being compared.

Examples

using System;
using Wolfgang.Extensions.IComparable;

DateTime today = DateTime.UtcNow.Date;
DateTime quarterStart = new DateTime(2026, 4, 1);
DateTime quarterEnd   = new DateTime(2026, 6, 30);

// True on any Q2 date, including the boundary days.
bool inQ2 = today.IsInRange(quarterStart, quarterEnd);

Exceptions

ArgumentNullException

value is null.