Implemented the functions

This commit is contained in:
MarcUs7i 2025-04-11 17:40:42 +02:00
parent 2d9718e247
commit 5ebee894e7
2 changed files with 73 additions and 17 deletions

View file

@ -4,31 +4,61 @@ namespace DigitSequence;
public sealed class DigitEnumerator : IEnumerator<int>
{
// TODO
//private readonly int _number;
private int _divisor;
private bool _started;
private readonly int _number;
/// <summary>
/// The constructor for <see cref="DigitEnumerator"/>
/// </summary>
/// <param name="number">The number</param>
public DigitEnumerator(int number)
{
// TODO
_number = Math.Abs(number);
}
/// <summary>
/// Moves to the next position
/// Default is invalid
/// </summary>
/// <returns>True, if the move was successful, false otherwise</returns>
public bool MoveNext()
{
// TODO
return false;
if (!_started)
{
_started = true;
_divisor = (int)Math.Pow(10, (int)Math.Log10(_number));
return _divisor >= 0;
}
_divisor /= 10;
return _divisor > 0;
}
/// <summary>
/// Resets the current position
/// </summary>
public void Reset()
{
// TODO
_started = false;
_divisor = 0;
}
public int Current => -1; // TODO
/// <summary>
/// Value of the current position
/// </summary>
public int Current => _divisor > 0 ? (_number / _divisor) % 10 : 0;
object IEnumerator.Current => null!; // TODO
/// <summary>
/// IEnumerator type for <seealso cref="Current"/>
/// </summary>
object IEnumerator.Current => Current;
/// <summary>
/// Disposes resources
/// </summary>
public void Dispose()
{
// TODO ?
// TODON'T! it doesn't seem that there is anything that has the need to be disposed
}
}