<PackageReference Include="System.Memory" Version="4.6.3" />

ReadOnlySequence<T>

public struct ReadOnlySequence<T>
Represents a sequence that can read a sequential series of .
public struct Enumerator<T>

An enumerator over the ReadOnlySequence<T>

public static readonly ReadOnlySequence<T> Empty

Returns empty ReadOnlySequence<T>

public SequencePosition End { get; }

A position to the end of the ReadOnlySequence<T>

public ReadOnlyMemory<T> First { get; }

Gets ReadOnlyMemory<T> from the first segment.

public bool IsEmpty { get; }

Determines if the ReadOnlySequence<T> is empty.

public bool IsSingleSegment { get; }

Determines if the ReadOnlySequence<T> contains a single ReadOnlyMemory<T> segment.

public long Length { get; }

Length of the ReadOnlySequence<T>.

public SequencePosition Start { get; }

A position to the start of the ReadOnlySequence<T>.

public ReadOnlySequence(ReadOnlySequenceSegment<T> startSegment, int startIndex, ReadOnlySequenceSegment<T> endSegment, int endIndex)

Creates an instance of ReadOnlySequence<T> from linked memory list represented by start and end segments and corresponding indexes in them.

public ReadOnlySequence(T[] array)

Creates an instance of ReadOnlySequence<T> from the T[].

public ReadOnlySequence(T[] array, int start, int length)

Creates an instance of ReadOnlySequence<T> from the T[], start and index.

public ReadOnlySequence(ReadOnlyMemory<T> memory)

Creates an instance of ReadOnlySequence<T> from the ReadOnlyMemory<T>. Consumer is expected to manage lifetime of memory until ReadOnlySequence<T> is not used anymore.

Returns an enumerator over the ReadOnlySequence<T>

public SequencePosition GetPosition(long offset)

Returns a new SequencePosition at an offset from the start of the sequence.

public SequencePosition GetPosition(long offset, SequencePosition origin)

Returns a new SequencePosition at an offset from the origin

public ReadOnlySequence<T> Slice(long start, long length)

Forms a slice out of the given ReadOnlySequence<T>, beginning at start, with length items

public ReadOnlySequence<T> Slice(long start, SequencePosition end)

Forms a slice out of the given ReadOnlySequence<T>, beginning at start, ending at end (inclusive).

public ReadOnlySequence<T> Slice(SequencePosition start, long length)

Forms a slice out of the given ReadOnlySequence<T>, beginning at start, with length items

public ReadOnlySequence<T> Slice(int start, int length)

Forms a slice out of the given ReadOnlySequence<T>, beginning at start, with length items

public ReadOnlySequence<T> Slice(int start, SequencePosition end)

Forms a slice out of the given ReadOnlySequence<T>, beginning at start, ending at end (inclusive).

public ReadOnlySequence<T> Slice(SequencePosition start, int length)

Forms a slice out of the given ReadOnlySequence<T>, beginning at 'start, with length items

Forms a slice out of the given ReadOnlySequence<T>, beginning at start, ending at end (inclusive).

Forms a slice out of the given ReadOnlySequence<T>, beginning at start, ending at the existing ReadOnlySequence<T>'s end.

public ReadOnlySequence<T> Slice(long start)

Forms a slice out of the given ReadOnlySequence<T>, beginning at start, ending at the existing ReadOnlySequence<T>'s end.

public bool TryGet(ref SequencePosition position, out ReadOnlyMemory memory, bool advance = true)

Tries to retrieve next segment after position and return its contents in memory. Returns false if end of ReadOnlySequence<T> was reached otherwise true. Sets position to the beginning of next segment if advance is set to true.