Class ComparableExtensions
Extension methods for
Inheritance
Namespace: X10D.Math
Assembly: X10D.dll
Syntax
public static class ComparableExtensions : object
Methods
| Improve this Doc View SourceBetween<T1, T2, T3>(T1, T2, T3, InclusiveOptions)
Determines if a specified value falls exclusively between a specified lower bound and upper bound.
Declaration
public static bool Between<T1, T2, T3>(this T1 value, T2 lower, T3 upper, InclusiveOptions inclusiveOptions = default(InclusiveOptions))
where T1 : IComparable<T2>, IComparable<T3> where T2 : IComparable<T3> where T3 : IComparable<T2>
Parameters
Type | Name | Description |
---|---|---|
T1 | value | The value to compare. |
T2 | lower | The exclusive lower bound. |
T3 | upper | The exclusive upper bound. |
InclusiveOptions | inclusiveOptions | The comparison clusivity. |
Returns
Type | Description |
---|---|
System.Boolean | true if |
Type Parameters
Name | Description |
---|---|
T1 | An |
T2 | The first comparison operand type. |
T3 | The second comparison operand type. |
Examples
int firstValue = 42;
int secondValue = 15;
int lower = 0;
int upper = 20;
Console.WriteLine($"{firstValue} between {lower} and {upper}?");
Console.WriteLine(firstValue.Between(lower, upper));
Console.WriteLine($"{secondValue} between {lower} and {upper}?");
Console.WriteLine(secondValue.Between(lower, upper));
// This will output the following:
// 42 between 0 and 20?
// False
// 15 between 0 and 20?
// True
|
Improve this Doc
View Source
Clamp<T>(T, T, T)
Returns the current value clamped to the inclusive range of lower
and upper
.
Declaration
public static T Clamp<T>(this T value, T lower, T upper)
where T : IComparable<T>
Parameters
Type | Name | Description |
---|---|---|
T | value | The value to be clamped. |
T | lower | The lower bound of the result. |
T | upper | The upper bound of the result. |
Returns
Type | Description |
---|---|
T |
|
Type Parameters
Name | Description |
---|---|
T | An |
Examples
int value = 42;
int lower = 0;
int upper = 20;
int clamped = value.Clamp(lower, upper);
// clamped will be 20
|
Improve this Doc
View Source
GreaterThan<T1, T2>(T1, T2)
Determines if the current value is greater than another value.
Declaration
public static bool GreaterThan<T1, T2>(this T1 value, T2 other)
where T1 : IComparable<T2>
Parameters
Type | Name | Description |
---|---|---|
T1 | value | The first value. |
T2 | other | The second value. |
Returns
Type | Description |
---|---|
System.Boolean | true if |
Type Parameters
Name | Description |
---|---|
T1 | An |
T2 | The comparison operand type. |
Examples
int first = 5;
int second = 10;
bool result = first.GreaterThan(second);
// result will be False
|
Improve this Doc
View Source
GreaterThanOrEqualTo<T1, T2>(T1, T2)
Determines if the current value is greater than or equal to another value.
Declaration
public static bool GreaterThanOrEqualTo<T1, T2>(this T1 value, T2 other)
where T1 : IComparable<T2>
Parameters
Type | Name | Description |
---|---|---|
T1 | value | The first value. |
T2 | other | The second value. |
Returns
Type | Description |
---|---|
System.Boolean | true if |
Type Parameters
Name | Description |
---|---|
T1 | An |
T2 | The comparison operand type. |
Examples
int first = 5;
int second = 10;
bool result = first.GreaterThanOrEqualTo(second);
// result will be False
|
Improve this Doc
View Source
LessThan<T1, T2>(T1, T2)
Determines if the current value is less than another value.
Declaration
public static bool LessThan<T1, T2>(this T1 value, T2 other)
where T1 : IComparable<T2>
Parameters
Type | Name | Description |
---|---|---|
T1 | value | The first value. |
T2 | other | The second value. |
Returns
Type | Description |
---|---|
System.Boolean | true if |
Type Parameters
Name | Description |
---|---|
T1 | An |
T2 | The comparison operand type. |
Examples
int first = 5;
int second = 10;
bool result = first.LessThan(second);
// result will be True
|
Improve this Doc
View Source
LessThanOrEqualTo<T1, T2>(T1, T2)
Determines if the current value is less than or equal to another value.
Declaration
public static bool LessThanOrEqualTo<T1, T2>(this T1 value, T2 other)
where T1 : IComparable<T2>
Parameters
Type | Name | Description |
---|---|---|
T1 | value | The first value. |
T2 | other | The second value. |
Returns
Type | Description |
---|---|
System.Boolean | true if |
Type Parameters
Name | Description |
---|---|
T1 | An |
T2 | The comparison operand type. |
Examples
int first = 5;
int second = 10;
bool result = first.LessThanOrEqualTo(second);
// result will be True
|
Improve this Doc
View Source
Max<T>(T, T)
Returns the maximum of two values.
Declaration
public static T Max<T>(this T value, T other)
where T : IComparable<T>
Parameters
Type | Name | Description |
---|---|---|
T | value | The first value. |
T | other | The second value. |
Returns
Type | Description |
---|---|
T |
|
Type Parameters
Name | Description |
---|---|
T | A type which implements |
Examples
int first = 5;
int second = 10;
int max = first.Max(second);
// max will be 10
|
Improve this Doc
View Source
Min<T>(T, T)
Returns the minimum of two values.
Declaration
public static T Min<T>(this T value, T other)
where T : IComparable<T>
Parameters
Type | Name | Description |
---|---|---|
T | value | The first value. |
T | other | The second value. |
Returns
Type | Description |
---|---|
T |
|
Type Parameters
Name | Description |
---|---|
T | A type which implements |
Examples
int first = 5;
int second = 10;
int min = first.Min(second);
// min will be 5