开发者

String stream object in .NET library

开发者 https://www.devze.com 2022-12-16 07:47 出处:网络
Is anyone aware of a .NET class for encapsulating a collection of objects (strings in my case) which allow for Stream-l开发者_开发知识库ike reading, seeking, etc.Essentially I need a List that has a G

Is anyone aware of a .NET class for encapsulating a collection of objects (strings in my case) which allow for Stream-l开发者_开发知识库ike 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.


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.


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


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号