CastArrayTFrom, TToSlice(Int32, Int32) Method

Gets a new CastArrayTFrom, TTo instance, which represents a subsection of the current instance with the specified startIndex and length. Please note that the size of TTo multiplied by startIndex must be divisible by the size of TFrom.

Definition

Namespace: KGySoft.Collections
Assembly: KGySoft.CoreLibraries (in KGySoft.CoreLibraries.dll) Version: 10.0.0
C#
public CastArray<TFrom, TTo> Slice(
	int startIndex,
	int length
)

Parameters

startIndex  Int32
The offset that points to the first item of the returned section.
length  Int32
The desired length of the returned section.

Return Value

CastArrayTFrom, TTo
The subsection of the current ArraySectionT instance with the specified startIndex and length.

Remarks

  Note

If the size of TTo multiplied by startIndex is not divisible by the size of TFrom, then this method throws an ArgumentException. If the targeted platform supports the SpanT type and misaligned memory access, then you can try to use the AsSpan property and the MemoryMarshal.Cast method.

Exceptions

ArgumentOutOfRangeExceptionstartIndex or length is out of range.
ArgumentExceptionThe size of TTo multiplied by startIndex is not divisible by the size of TFrom.

See Also