Op Englesch liesen Editéieren

Deelen iwwer


Index.GetOffset(Int32) Method

Definition

Calculates the offset from the start of the collection using the specified collection length.

C#
public int GetOffset(int length);

Parameters

length
Int32

The length of the collection that the Index will be used with. Must be a positive value.

Returns

The offset.

Remarks

For performance reasons, this method does not validate if length or the returned value are negative. It also doesn't validate if the returned value is greater than length.

Collections are not expected to have a negative length/count. If this method's returned offset is negative and is then used to index a collection, the runtime will throw ArgumentOutOfRangeException, which will have the same effect as validation.

Applies to

Produkt Versiounen
.NET Core 3.0, Core 3.1, 5, 6, 7, 8, 9, 10
.NET Standard 2.0 (package-provided), 2.1