Skip to content

How to know if I'm on the last segment of a sequence? #111551

Answered by teo-tsirpanis
paulomorgado asked this question in Q&A
Discussion options

You must be logged in to vote

It appears to me that you are using ReadOnlySequence<T> wrong. ReadOnlySequence<T> does not represent a sequence of sequences, but a single sequence that is backed by one or maybe more contiguous buffers. A sequence backed by a single array [1, 2, 3, 4, 5, 6, 7, 8, 9], and a sequence backed by three arrays [1, 2, 3], [4, 5, 6] and [7, 8, 9] represent the same thing.

If the underlying structure of the sequence is important to your algorithm, and you need to answer questions like whether you are on the last segment of a sequence, you should be using a different API like IReadOnlyCollection<ReadOnlyMemory<T>>.

Replies: 2 comments 1 reply

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
1 reply
@paulomorgado
Comment options

Answer selected by paulomorgado
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants