using System.Collections; namespace Numbers.NumberFactory; /// /// An enumerator for a list of numbers /// /// public sealed class NumbersEnumerator : IEnumerator { /// /// Creates a new instance of which will enumerate over the given list /// /// List to iterate over public NumbersEnumerator(List list) { List = list; Index = -1; } private int Index { get; set; } private List List { get; } public long Current { get { if (Index < 0 || Index >= List.Count) { return -1; } return List[Index]; } } public void Dispose() { } object IEnumerator.Current => Current; public bool MoveNext() { if (Index >= List.Count - 1) { return false; } Index++; return true; } public void Reset() { Index = -1; } }