using System.Collections; namespace DigitSequence; public sealed class DigitEnumerator : IEnumerator { private int _divisor; private bool _started; private readonly int _number; /// /// The constructor for /// /// The number public DigitEnumerator(int number) { _number = Math.Abs(number); } /// /// Moves to the next position /// Default is invalid /// /// True, if the move was successful, false otherwise public bool MoveNext() { if (!_started) { _started = true; _divisor = (int)Math.Pow(10, (int)Math.Log10(_number)); return _divisor >= 0; } _divisor /= 10; return _divisor > 0; } /// /// Resets the current position /// public void Reset() { _started = false; _divisor = 0; } /// /// Value of the current position /// public int Current => _divisor > 0 ? (_number / _divisor) % 10 : 0; /// /// IEnumerator type for /// object IEnumerator.Current => Current; /// /// Disposes resources /// public void Dispose() { // TODON'T! it doesn't seem that there is anything that has the need to be disposed } }