In This Article

Range Struct

Represents an ordered pair of min and max values.

public struct Range : IEquatable<Range>
Implements:
IEquatable<Range>

Constructors

Range(int)

Initializes an instance of the structure with the specified min and max value.

public Range(int value)
Parameter Type Description
value int

The value to use for both the min and max.

Range(int, int)

Initializes an instance of the structure with the specified min and max values.

public Range(int min, int max)
Parameter Type Description
min int

The minimum value of the range.

max int

The maximum value of the range.

Properties

IsNormalized

Indicates whether the range is normalized (the maximum value is greater than or equal to the minimum).

public readonly bool IsNormalized { get; }

Property Value

bool:

true if the range is normalized; otherwise, false.

IsZeroLength

Indicates whether the range has a zero length.

public readonly bool IsZeroLength { get; }

Property Value

bool:

true if the range has a zero length; otherwise, false.

Length

The length of this Range.

public readonly int Length { get; }

Property Value

int

Max

The maximum value of this Range.

public int Max { readonly get; set; }

Property Value

int

Min

The minimum value of this Range.

public int Min { readonly get; set; }

Property Value

int

Methods

Contains(Range)

Returns whether the range inclusively contains the specified Range.

public readonly bool Contains(Range range)
Parameter Type Description
range Range

The Range to check.

Returns

bool:

true if the range inclusively contains the specified Range; otherwise, false.

Contains(int)

Returns whether the range inclusively contains the specified value.

public readonly bool Contains(int value)
Parameter Type Description
value int

The value to check.

Returns

bool:

true if the range inclusively contains the specified value; otherwise, false.

Equals(Range)

Indicates whether the current object is equal to another object of the same type.

public readonly bool Equals(Range other)
Parameter Type Description
other Range

An object to compare with this object.

Returns

bool:

true if the current object is equal to the other parameter; otherwise, false.

Equals(object?)

Indicates whether this instance and a specified object are equal.

public override readonly bool Equals(object? obj)
Parameter Type Description
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 readonly int GetHashCode()

Returns

int:

A 32-bit signed integer that is the hash code for this instance.

Intersect(Range, Range)

Returns the intersection of two Range objects.

public static Range? Intersect(Range range1, Range range2)
Parameter Type Description
range1 Range

The first Range to examine.

range2 Range

The second Range to examine.

Returns

Range?:

The intersection of two Range objects.

IntersectsWith(Range)

Returns whether the range intersects with the specified Range.

public readonly bool IntersectsWith(Range range)
Parameter Type Description
range Range

The Range to check.

Returns

bool:

true if the range intersects with the specified Range; otherwise, false.

Normalize()

Normalizes the range values (ensures that the maximum value is greater than or equal to the minimum).

public void Normalize()

OverlapsWith(Range)

Returns whether the Range overlaps with, or crosses, the specified Range.

public readonly bool OverlapsWith(Range range)
Parameter Type Description
range Range

The Range to examine.

Returns

bool:

true if the Range overlaps with, or crosses, the specified Range; otherwise, false.

ToString()

Returns the string representation of this object.

public override readonly string ToString()

Returns

string:

The string representation of this object.

Union(Range)

Changes this Range to be the union of this Range with another Range.

public void Union(Range range)
Parameter Type Description
range Range

The Range with which to merge.

Operators

operator ==(Range, Range)

Compares two Range objects. The result specifies whether the values of the Min and Max properties of the two Range objects are equal.

public static bool operator ==(Range left, Range right)
Parameter Type Description
left Range

A Range to compare.

right Range

A Range to compare.

Returns

bool:

true if the Min and Max values of left and right are equal; otherwise, false.

operator !=(Range, Range)

Compares two Range objects. The result specifies whether the values of the Min and Max properties of the two Range objects are unequal.

public static bool operator !=(Range left, Range right)
Parameter Type Description
left Range

A Range to compare.

right Range

A Range to compare.

Returns

bool:

true if the Min and Max values of left and right are unequal; otherwise, false.

Inherited Members