-
Notifications
You must be signed in to change notification settings - Fork 0
IComparable Extensions
Andrzej Kebab edited this page Jan 21, 2024
·
2 revisions
This utility library provides extension methods for types implementing IComparable<T> to simplify common comparison operations.
Determines whether the specified value is between the lower and upper bounds.
using UtilityLibrary.Core;
int value = 5;
int lowerBound = 2;
int upperBound = 8;
bool isBetween = value.Between(lowerBound, upperBound, includeLowerBound: true, includeUpperBound: true);-
value(T): The value to compare. -
lowerBound(T): The lower bound. -
upperBound(T): The upper bound. -
includeLowerBound(bool): If set totrue, includes the lower bound in the comparison. -
includeUpperBound(bool): If set totrue, includes the upper bound in the comparison.
- bool:
Trueif the specified value is between the bounds; otherwise,False.
Clamps the specified value within the min and max range.
using UtilityLibrary.Core;
int value = 15;
int min = 5;
int max = 10;
int clampedValue = value.Clamp(min, max);-
value(T): The value to clamp. -
min(T): The minimum value. -
max(T): The maximum value.
- T: The clamped value.
Determines whether the specified value is less than the other specified value.
using UtilityLibrary.Core;
int value = 5;
int other = 10;
bool isLessThan = value.LessThan(other);-
value(T): The value to compare. -
other(T): The other value to compare.
- bool:
Trueif the specified value is less than the other value; otherwise,False.
Determines whether the specified value is less than or equal to the other specified value.
using UtilityLibrary.Core;
int value = 5;
int other = 5;
bool isLessOrEqual = value.LessOrEqual(other);-
value(T): The value to compare. -
other(T): The other value to compare.
- bool:
Trueif the specified value is less than or equal to the other value; otherwise,False.
Determines whether the specified value is greater than the other specified value.
using UtilityLibrary.Core;
int value = 10;
int other = 5;
bool isGreaterThan = value.GreaterThan(other);-
value(T): The value to compare. -
other(T): The other value to compare.
- bool:
Trueif the specified value is greater than the other value; otherwise,False.
Determines whether the specified value is greater than or equal to the other specified value.
using UtilityLibrary.Core;
int value = 10;
int other = 10;
bool isGreaterOrEqual = value.GreaterOrEqual(other);-
value(T): The value to compare. -
other(T): The other value to compare.
- bool:
Trueif the specified value is greater than or equal to the other value; otherwise,False.