Table of Contents

Struct Range<T>

Namespace
Utils.Range
Assembly
Utils.dll

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

T

A comparable type that supports ordering.

Implements
Inherited Members
Extension Methods

Constructors

Range(T)

Constructs a degenerate range that represents a single value [value..value].

public Range(T value)

Parameters

value T

The 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

start T

The lower boundary of the range.

end T

The upper boundary of the range.

containsStart bool

Indicates whether start belongs to the range.

containsEnd bool

Indicates whether end belongs to the range.

Properties

ContainsEnd

Gets a value indicating whether End is included in the range.

public bool ContainsEnd { get; }

Property Value

bool

ContainsStart

Gets a value indicating whether Start is included in the range.

public bool ContainsStart { get; }

Property Value

bool

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

other IRange<T>

The range to compare with.

Returns

bool

true when other is entirely inside this range; otherwise, false.

Contains(T)

Determines whether the supplied value lies within the range boundaries.

public bool Contains(T value)

Parameters

value T

The value to test.

Returns

bool

true if value is contained in the range; otherwise, false.

Equals(Range<T>?)

Determines whether another range has the same boundaries and inclusiveness flags.

public bool Equals(Range<T>? other)

Parameters

other Range<T>?

The range to compare with.

Returns

bool

true when both ranges describe the same interval; otherwise, false.

Equals(object?)

Indicates whether this instance and a specified object are equal.

public override bool Equals(object? obj)

Parameters

obj object

The object to compare with the current instance.

Returns

bool

true if obj and 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

other IRange<T>

The range to intersect with.

Returns

IRange<T>[]

A new range representing the overlap, or null when the ranges are disjoint.

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

other IRange<T>

The range to compare with.

Returns

bool

true when both ranges can coexist in the same Ranges<T>; otherwise, false.

Overlap(IRange<T>)

Determines whether this range overlaps with another range.

public bool Overlap(IRange<T> other)

Parameters

other IRange<T>

The range to test against.

Returns

bool

true when the two ranges share at least one value; otherwise, false.

Overlap(IRange<T>, IRange<T>)

Determines whether two ranges overlap.

public static bool Overlap(IRange<T> a, IRange<T> b)

Parameters

a IRange<T>

The first range.

b IRange<T>

The second range.

Returns

bool

true when the two ranges share at least one value; otherwise, false.

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

formatProvider IFormatProvider

Culture 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

format string

Custom 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

format string

Custom format applied to the numeric boundaries.

formatProvider IFormatProvider

Culture used when formatting the numeric boundaries.

Returns

string

A string representation of the current range.