Struct Range<T>
Represents a range of values with a start and end, plus inclusivity flags. Stored as a struct for efficient copying.
public readonly struct Range<T> : IRange<T>, IFormattable, IEquatable<Range<T>?> where T : IComparable<T>
Type Parameters
TA comparable type that supports ordering.
- Implements
-
IRange<T>IEquatable<Range<T>?>
- Inherited Members
- Extension Methods
Constructors
Range(T)
Constructs a degenerate range that represents a single value [value..value].
public Range(T value)
Parameters
valueTThe value captured by the range.
Range(T, T, bool, bool)
Initializes a new Range<T> with the specified boundaries and inclusiveness flags.
public Range(T start, T end, bool containsStart = true, bool containsEnd = true)
Parameters
startTThe lower boundary of the range.
endTThe upper boundary of the range.
containsStartboolIndicates whether
startbelongs to the range.containsEndboolIndicates whether
endbelongs to the range.
Properties
ContainsEnd
Gets a value indicating whether End is included in the range.
public bool ContainsEnd { get; }
Property Value
ContainsStart
Gets a value indicating whether Start is included in the range.
public bool ContainsStart { get; }
Property Value
End
Gets the inclusive or exclusive ending boundary of the range.
public T End { get; }
Property Value
- T
Start
Gets the inclusive or exclusive starting boundary of the range.
public T Start { get; }
Property Value
- T
Methods
Contains(IRange<T>)
Determines whether this range completely contains another range.
public bool Contains(IRange<T> other)
Parameters
otherIRange<T>The range to compare with.
Returns
Contains(T)
Determines whether the supplied value lies within the range boundaries.
public bool Contains(T value)
Parameters
valueTThe value to test.
Returns
Equals(Range<T>?)
Determines whether another range has the same boundaries and inclusiveness flags.
public bool Equals(Range<T>? other)
Parameters
otherRange<T>?The range to compare with.
Returns
Equals(object?)
Indicates whether this instance and a specified object are equal.
public override bool Equals(object? obj)
Parameters
objobjectThe object to compare with the current instance.
Returns
- bool
true if
objand this instance are the same type and represent the same value; otherwise, false.
GetHashCode()
Returns the hash code for this instance.
public override int GetHashCode()
Returns
- int
A 32-bit signed integer that is the hash code for this instance.
Intersect(IRange<T>)
Computes the intersection of this range with another one if possible.
public IRange<T>[] Intersect(IRange<T> other)
Parameters
otherIRange<T>The range to intersect with.
Returns
IsCompatibleWith(IRange<T>)
Determines whether the current range model is compatible with another range for aggregation in the same collection.
public bool IsCompatibleWith(IRange<T> other)
Parameters
otherIRange<T>The range to compare with.
Returns
Overlap(IRange<T>)
Determines whether this range overlaps with another range.
public bool Overlap(IRange<T> other)
Parameters
otherIRange<T>The range to test against.
Returns
Overlap(IRange<T>, IRange<T>)
Determines whether two ranges overlap.
public static bool Overlap(IRange<T> a, IRange<T> b)
Parameters
Returns
ToString()
Converts this range to a string using default formatting.
public override string ToString()
Returns
- string
A string representation of the current range.
ToString(IFormatProvider?)
Converts this range to a string using the supplied format provider.
public string ToString(IFormatProvider? formatProvider)
Parameters
formatProviderIFormatProviderCulture used when formatting the numeric boundaries.
Returns
- string
A string representation of the current range.
ToString(string?)
Converts this range to a string using the supplied format string.
public string ToString(string? format)
Parameters
formatstringCustom format applied to the numeric boundaries.
Returns
- string
A string representation of the current range.
ToString(string?, IFormatProvider?)
Converts this range to a string using the supplied format string and provider.
public string ToString(string? format, IFormatProvider? formatProvider)
Parameters
formatstringCustom format applied to the numeric boundaries.
formatProviderIFormatProviderCulture used when formatting the numeric boundaries.
Returns
- string
A string representation of the current range.