Range<T> Struct
Represents a range of comparable values with support for various inclusion/exclusion boundary checks.
public readonly struct Range<T> : IEquatable<Range<T>> where T : IComparable<T>Type parameters
T
Example
var range = new Range<int>(1, 10);
Assert.True(range.IsInRangeInclusive(5));
Assert.False(range.IsInRangeInclusive(15));- Implements
Constructors
| Name | Description |
|---|---|
| Range(T, T) | Initializes a new instance of the Range<T> struct. |
Range(T, T)
Range.csInitializes a new instance of the Range<T> struct.
public Range(T from, T to)Properties
| Name | Description |
|---|---|
| From | Gets the start value of the range. |
| To | Gets the end value of the range. |
From
Range.csGets the start value of the range.
public T From { get; }Property value
T
To
Range.csGets the end value of the range.
public T To { get; }Property value
T
Methods
| Name | Description |
|---|---|
| Equals(Range<T>) | |
| Equals(object?) | |
| GetHashCode() | |
| Intersect(Range<T>) | Returns the values that are in both this range and the specified range, inclusive of boundaries. |
| IsInRangeExclusive(Range<T>) | Determines whether the specified range is fully contained within this range, exclusive of boundaries. |
| IsInRangeExclusive(T) | Determines whether the specified value is within this range, exclusive of boundaries. |
| IsInRangeInclusive(Range<T>) | Determines whether the specified range is fully contained within this range, inclusive of boundaries. |
| IsInRangeInclusive(T) | Determines whether the specified value is within this range, inclusive of boundaries. |
| IsInRangeLowerInclusive(Range<T>) | Determines whether the specified range is fully contained within this range, inclusive of the lower bound and exclusive of the upper bound. |
| IsInRangeLowerInclusive(T) | Determines whether the specified value is within this range, inclusive of the lower bound and exclusive of the upper bound. |
| IsInRangeUpperInclusive(Range<T>) | Determines whether the specified range is fully contained within this range, exclusive of the lower bound and inclusive of the upper bound. |
| IsInRangeUpperInclusive(T) | Determines whether the specified value is within this range, exclusive of the lower bound and inclusive of the upper bound. |
| Overlaps(Range<T>) | Determines whether this range and the specified range have at least one value in common, inclusive of boundaries. |
| ToString() |
GetHashCode()
Range.csIntersect(Range<T>)
Range.csReturns the values that are in both this range and the specified range, inclusive of boundaries.
IsInRangeLowerInclusive overloads
IsInRangeLowerInclusive(Range<T>)
Range.csIsInRangeLowerInclusive(T)
Range.csIsInRangeUpperInclusive overloads
IsInRangeUpperInclusive(Range<T>)
Range.csIsInRangeUpperInclusive(T)
Range.csOverlaps(Range<T>)
Range.csToString()
Range.csOperators
| Name | Description |
|---|---|
| operator ==(Range<T>, Range<T>) | |
| operator !=(Range<T>, Range<T>) |