Struct Range<T>
Defines a range of values.
Inherited Members
Namespace: TheXDS.MCART.Types
Assembly: MCART.dll
Syntax
public struct Range<T> : IRange<T>, IEquatable<IRange<T>>, ICloneable<Range<T>>, ICloneable where T : IComparable<T>
Type Parameters
| Name | Description |
|---|---|
| T | Base type of the value range. |
Constructors
| Edit this page View SourceRange(T)
Initializes a new instance of the Range<T> structure.
Declaration
public Range(T maximum)
Parameters
| Type | Name | Description |
|---|---|---|
| T | maximum | Maximum value of the range, inclusive. |
Range(T, bool)
Initializes a new instance of the Range<T> structure.
Declaration
public Range(T maximum, bool inclusive)
Parameters
| Type | Name | Description |
|---|---|---|
| T | maximum | Maximum value of the range. |
| bool | inclusive | If set to true, the maximum value will be included in the range. |
Range(T, T)
Initializes a new instance of the Range<T> structure.
Declaration
public Range(T minimum, T maximum)
Parameters
| Type | Name | Description |
|---|---|---|
| T | minimum | Minimum value of the range, inclusive. |
| T | maximum | Maximum value of the range, inclusive. |
Range(T, T, bool)
Initializes a new instance of the Range<T> structure.
Declaration
public Range(T minimum, T maximum, bool inclusive)
Parameters
| Type | Name | Description |
|---|---|---|
| T | minimum | Minimum value of the range. |
| T | maximum | Maximum value of the range. |
| bool | inclusive | If set to true, both minimum and maximum values will be included in the range. |
Range(T, T, bool, bool)
Initializes a new instance of the Range<T> structure.
Declaration
public Range(T minimum, T maximum, bool minInclusive, bool maxInclusive)
Parameters
| Type | Name | Description |
|---|---|---|
| T | minimum | Minimum value of the range. |
| T | maximum | Maximum value of the range. |
| bool | minInclusive | If set to true, the minimum value will be included in the range. |
| bool | maxInclusive | If set to true, the maximum value will be included in the range. |
Properties
| Edit this page View SourceMaxInclusive
Gets or sets a value that determines whether the maximum value is part of the range.
Declaration
public bool MaxInclusive { readonly get; set; }
Property Value
| Type | Description |
|---|---|
| bool |
Maximum
Maximum value of the range.
Declaration
public T Maximum { readonly get; set; }
Property Value
| Type | Description |
|---|---|
| T |
MinInclusive
Gets or sets a value that determines whether the minimum value is part of the range.
Declaration
public bool MinInclusive { readonly get; set; }
Property Value
| Type | Description |
|---|---|
| bool |
Minimum
Minimum value of the range.
Declaration
public T Minimum { readonly get; set; }
Property Value
| Type | Description |
|---|---|
| T |
Methods
| Edit this page View SourceClone()
Creates a copy of this instance.
Declaration
public readonly Range<T> Clone()
Returns
| Type | Description |
|---|---|
| Range<T> | A copy of this instance of type Range<T>. |
Equals(object?)
Indicates whether this instance and a specified object are equal.
Declaration
public override readonly bool Equals(object? obj)
Parameters
| Type | Name | Description |
|---|---|---|
| object | obj | The object to compare with the current instance. |
Returns
| Type | Description |
|---|---|
| bool |
Overrides
| Edit this page View SourceEquals(IRange<T>?)
Indicates whether this instance and a specified object are equal.
Declaration
public readonly bool Equals(IRange<T>? other)
Parameters
| Type | Name | Description |
|---|---|---|
| IRange<T> | other | The object to compare with the current instance. |
Returns
| Type | Description |
|---|---|
| bool |
GetHashCode()
Returns the hash code for this instance.
Declaration
public override readonly int GetHashCode()
Returns
| Type | Description |
|---|---|
| int | The hash code for this instance. |
Overrides
| Edit this page View SourceIntersect(IRange<T>)
Gets an intersection range from this and another specified range.
Declaration
public readonly Range<T> Intersect(IRange<T> other)
Parameters
| Type | Name | Description |
|---|---|---|
| IRange<T> | other | Range to intersect. |
Returns
| Type | Description |
|---|---|
| Range<T> | The intersection between this range and |
Intersects(IRange<T>)
Determines if a Range<T> intersects with this one.
Declaration
public readonly bool Intersects(IRange<T> other)
Parameters
| Type | Name | Description |
|---|---|---|
| IRange<T> | other | Range to check. |
Returns
| Type | Description |
|---|---|
| bool |
IsWithin(T)
Checks if a T value is within this Range<T>.
Declaration
public readonly bool IsWithin(T value)
Parameters
| Type | Name | Description |
|---|---|---|
| T | value | Value to check. |
Returns
| Type | Description |
|---|---|
| bool |
Join(IRange<T>)
Combines this Range<T> with another.
Declaration
public readonly Range<T> Join(IRange<T> other)
Parameters
| Type | Name | Description |
|---|---|---|
| IRange<T> | other |
Returns
| Type | Description |
|---|---|
| Range<T> |
Parse(string)
Creates a Range<T> from a string.
Declaration
[RequiresUnreferencedCode("The method obtains a collection of types without direct references, so it is not compatible with trimming.")]
[RequiresDynamicCode("The method makes calls to dynamic code, so it is not compatible with trimming.")]
public static Range<T> Parse(string value)
Parameters
| Type | Name | Description |
|---|---|---|
| string | value | Value from which to create a Range<T>. |
Returns
| Type | Description |
|---|---|
| Range<T> | The created Range<T>. |
Exceptions
| Type | Condition |
|---|---|
| FormatException | Thrown if the conversion fails. |
ToString()
Converts this Range<T> to its string representation.
Declaration
public override readonly string ToString()
Returns
| Type | Description |
|---|---|
| string | A string representation of this Range<T>. |
Overrides
| Edit this page View SourceTryParse(string, out Range<T>)
Attempts to create a Range<T> from a string.
Declaration
[RequiresUnreferencedCode("The method obtains a collection of types without direct references, so it is not compatible with trimming.")]
[RequiresDynamicCode("The method makes calls to dynamic code, so it is not compatible with trimming.")]
public static bool TryParse(string value, out Range<T> range)
Parameters
| Type | Name | Description |
|---|---|---|
| string | value | Value from which to create a Range<T>. |
| Range<T> | range | The created Range<T>. |
Returns
| Type | Description |
|---|---|
| bool |
Operators
| Edit this page View Sourceoperator +(Range<T>, Range<T>)
Unites two value ranges.
Declaration
public static Range<T> operator +(Range<T> left, Range<T> right)
Parameters
| Type | Name | Description |
|---|---|---|
| Range<T> | left | Left operand. |
| Range<T> | right | Right operand. |
Returns
| Type | Description |
|---|---|
| Range<T> | The union of both Range<T>. If the ranges don't intersect, all missing values will be included. |
operator ==(Range<T>, Range<T>)
Compares two instances of Range<T> for equality.
Declaration
public static bool operator ==(Range<T> left, Range<T> right)
Parameters
| Type | Name | Description |
|---|---|---|
| Range<T> | left | Object to compare. |
| Range<T> | right | Object to compare against. |
Returns
| Type | Description |
|---|---|
| bool |
operator !=(Range<T>, Range<T>)
Declaration
public static bool operator !=(Range<T> left, Range<T> right)
Parameters
| Type | Name | Description |
|---|---|---|
| Range<T> | left | Object to compare. |
| Range<T> | right | Object to compare against. |
Returns
| Type | Description |
|---|---|
| bool |