2

Is anyone aware of a .NET class for encapsulating a collection of objects (strings in my case) which allow for Stream-like reading, seeking, etc. Essentially I need a List that has a GetNext method that will return the next object and update the current reading position.

This wouldn't be hard to impliment (possibly with extension methods) but I wanted to leverage any currently developed .NET classes that may already exist.

EDIT: I want to add that the data will always be accessed in a forward manner (i.e. no need to seek to a spedific position) or just reset to zero. So it seems like an IEnumerator may work.

0

3 Answers 3

5

This is what IEnumerable/IEnumerator does. Just call GetEnumerator() on your list and use the IEnumerator's Current/MoveNext() members.

If you want more functionality in terms of moving the current record pointer, you might find what you need just using the Take() extension method. Implementing an IEnumerable which maintains internal state is also farily easy.

Sign up to request clarification or add additional context in comments.

1 Comment

That worked. Good idea. I didn't even consider just using the Enumerator to perform this task.
2

There's always IEnumerable. Of course, the limitation is that you can't seek backwards.

Comments

-1

BinaryReader/BinaryWriter has functions for serializing all of the primitive types. As long as you know what type to expect, this should work for you. Seeking will be hard if you expect it to maintain string boundaries, but will work great for forward-only reading of all primitives.

1 Comment

The poster just wants the objects, not the data.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.