Added ArrayStream class

master
Harald Wolff-Thobaben 2020-11-19 20:39:27 +01:00
parent f8ccd0d505
commit d07d0e3dae
1 changed files with 41 additions and 0 deletions

41
ArrayStream.cs 100644
View File

@ -0,0 +1,41 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
namespace ln.collections
{
public class ArrayStream<T>
{
public T[] Elements { get; }
public int Position { get; set; }
public ArrayStream(T[] elements)
{
Elements = elements;
Position = 0;
}
public ArrayStream(IEnumerable<T> elements)
{
Elements = elements.ToArray();
Position = 0;
}
public T Current => Elements[Position];
public T Next() => Next(1);
public T Next(int forward) => Elements[Position + 1 + forward];
public bool MoveNext()
{
if (Position >= Elements.Length)
throw new EndOfStreamException();
Position++;
return (Position < Elements.Length);
}
public bool EndOfStream => (Position < Elements.Length);
}
}