Class IntRange
Represent a range has start and end indexes.
public class IntRange : IEquatable<IntRange>
- Inheritance
-
IntRange
- Implements
- Inherited Members
Remarks
Range is used by the C# compiler to support the range syntax.
int[] someArray = new int[5] { 1, 2, 3, 4, 5 };
int[] subArray1 = someArray[0..2]; // { 1, 2 }
int[] subArray2 = someArray[1..^0]; // { 2, 3, 4, 5 }
Constructors
IntRange(Index, Index)
Construct a Range object using the start and end indexes.
public IntRange(Index start, Index end)
Parameters
start
IndexRepresent the inclusive start index of the range.
end
IndexRepresent the exclusive end index of the range.
Properties
All
Create a Range object starting from first element to the end.
public static IntRange All { get; }
Property Value
End
Represent the exclusive end index of the Range.
public Index End { get; }
Property Value
Start
Represent the inclusive start index of the Range.
public Index Start { get; }
Property Value
Methods
EndAt(Index)
Create a Range object starting from first element in the collection to the end Index.
public static IntRange EndAt(Index end)
Parameters
end
Index
Returns
Equals(IntRange)
Indicates whether the current Range object is equal to another Range object.
public bool Equals(IntRange other)
Parameters
other
IntRangeAn object to compare with this object
Returns
Equals(object?)
Indicates whether the current Range object is equal to another object of the same type.
public override bool Equals(object? value)
Parameters
value
objectAn object to compare with this object
Returns
GetHashCode()
Returns the hash code for this instance.
public override int GetHashCode()
Returns
GetOffsetAndLength(int)
Calculate the start offset and length of range object using a collection length.
public (int Offset, int Length) GetOffsetAndLength(int length)
Parameters
length
intThe length of the collection that the range will be used with. length has to be a positive value.
Returns
Remarks
For performance reason, we don't validate the input length parameter against negative values. It is expected Range will be used with collections which always have non negative length/count. We validate the range is inside the length scope though.
StartAt(Index)
Create a Range object starting from start index to the end of the collection.
public static IntRange StartAt(Index start)
Parameters
start
Index
Returns
ToString()
Converts the value of the current Range object to its equivalent string representation.
public override string ToString()