47 lines
No EOL
1.5 KiB
C#
47 lines
No EOL
1.5 KiB
C#
using System.Collections;
|
|
|
|
namespace DigitSequence;
|
|
|
|
public sealed class Digits(int number) : IEnumerable<int>, IComparable<Digits>
|
|
{
|
|
private readonly int _number = Math.Abs(number);
|
|
|
|
/// <summary>
|
|
/// Compares to another digit
|
|
/// </summary>
|
|
/// <param name="other">The other digit</param>
|
|
/// <returns>The default compared value</returns>
|
|
public int CompareTo(Digits? other)
|
|
{
|
|
if (other == null)
|
|
{
|
|
return 1;
|
|
}
|
|
|
|
if (ReferenceEquals(this, other))
|
|
{
|
|
return 0;
|
|
}
|
|
|
|
return _number.CompareTo(other._number);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Gets the enumerator of type <see cref="int"/>
|
|
/// </summary>
|
|
/// <returns>The <see cref="IEnumerator"/> of type <see cref="int"/></returns>
|
|
public IEnumerator<int> GetEnumerator() => new DigitEnumerator(number);
|
|
|
|
/// <summary>
|
|
/// Gets the enumerator as an <see cref="object"/> of type <see cref="IEnumerator"/>
|
|
/// </summary>
|
|
/// <returns>The <see cref="IEnumerator"/></returns>
|
|
// I'm gonna be a wikipedia author with that many references xD
|
|
IEnumerator IEnumerable.GetEnumerator() => GetEnumerator();
|
|
|
|
/// <summary>
|
|
/// The overriden Method to get the <see cref="string"/> representation of the current object
|
|
/// </summary>
|
|
/// <returns>The values of <see cref="Digits"/> in a <see cref="string"/> format</returns>
|
|
public override string ToString() => _number.ToString();
|
|
} |