Range Class
Represents an ordered pair of min and max values.
public class Range
- Inheritance:
- object object
Constructors
Range()
Initializes an instance of the class.
public Range()
Range(int, int)
Initializes an instance of the class.
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
Empty
An empty Range.
IsEmpty
Indicates whether the Range is empty.
IsNormalized
Indicates whether the range is normalized (the maximum value is greater than or equal to the minimum).
public bool IsNormalized { get; }
Property Value
- bool:
trueif the range is normalized; otherwise,false.
Length
The length of this Range.
public int Length { get; }
Property Value
Remarks
This value can be negative if the range is not normalized.
Max
The maximum value of this Range.
Min
The minimum value of this Range.
Methods
Contains(Range)
Returns whether the range inclusively contains the specified Range.
public bool Contains(Range range)
| Parameter | Type | Description |
|---|---|---|
| range | Range | The Range to check. |
Returns
Contains(int)
Returns whether the range inclusively contains the specified value.
public bool Contains(int value)
| Parameter | Type | Description |
|---|---|---|
| value | int | The value to check. |
Returns
- bool:
trueif the range inclusively contains the specified value; otherwise,false.
Equals(object?)
Determines whether the specified object is equal to the current object.
public override bool Equals(object? obj)
| Parameter | Type | Description |
|---|---|---|
| obj | object | The object to compare with the current object. |
Returns
- bool:
trueif the specified object is equal to the current object; otherwise,false.
GetHashCode()
Serves as the default hash function.
IntersectsWith(Range)
Returns whether the range intersects with the specified Range.
public bool IntersectsWith(Range range)
| Parameter | Type | Description |
|---|---|---|
| range | Range | The Range to check. |
Returns
Normalize()
Normalizes the range values (ensures that the maximum value is greater than or equal to the minimum).
public void Normalize()
ToString()
Returns the string representation of this object.
Union(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
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
Inherited Members
- object.GetType()
- object.MemberwiseClone()
- object.Equals(object, object)
- object.ReferenceEquals(object, object)