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
valueTThe value to compare.
lowerBoundTThe exclusive lower bound of the range.
upperBoundTThe exclusive upper bound of the range.
Returns
Type Parameters
TThe 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
valueis 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
valueTThe value to compare.
lowerBoundTThe inclusive lower bound of the range.
upperBoundTThe inclusive upper bound of the range.
Returns
- bool
true if
valueis greater than or equal tolowerBoundand less than or equal toupperBound; otherwise, false.
Type Parameters
TThe 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
valueis null.