Sprog

Index Struct

Definition

Represents a type that can be used to index a collection either from the beginning or the end.

public value class Index : IEquatable<Index>
public readonly struct Index : IEquatable<Index>
type Index = struct
Public Structure Index
Implements IEquatable(Of Index)
Inheritance
Implements

Remarks

Index is used by the C# compiler to support the ^ or "index from end" operator:

int[] someArray = new int[5] { 1, 2, 3, 4, 5 };
int lastElement = someArray[^1]; // lastElement = 5

Constructors

Name Description
Index(Int32, Boolean)

Construct an Index using a value and indicating if the index is from the start or from the end.

Properties

Name Description
End

Create an Index pointing at beyond last element.

IsFromEnd

Indicates whether the index is from the start or the end.

Start

Create an Index pointing at first element.

Value

Returns the index value.

Methods

Name Description
Equals(Index)

Indicates whether the current Index object is equal to another Index object.

Equals(Object)

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

FromEnd(Int32)

Create an Index from the end at the position indicated by the value.

FromStart(Int32)

Create an Index from the start at the position indicated by the value.

GetHashCode()

Returns the hash code for this instance.

GetOffset(Int32)

Calculate the offset from the start using the giving collection length.

ToString()

Converts the value of the current Index object to its equivalent string representation.

Operators

Name Description
Implicit(Int32 to Index)

Converts integer number to an Index.

Applies to