예제 #1
0
 private RomanNumeralPair GetNumberPairInstance(RomanNumeralsType value)
 {
     return(new RomanNumeralPair
     {
         NumericValue = Convert.ToInt32(value),
         RomanNumeralRepresentation = value.ToString()
     });
 }
예제 #2
0
        public string ConvertRomanNumeral(int number)
        {
            if (number < 1 || number >= 4000)
            {
                throw new IndexOutOfRangeException("The number supplied is out of the expected range (1 - 4000).");
            }

            var builder = new StringBuilder();

            var romanNumbers = Enum.GetValues(typeof(RomanNumeralsType)).Cast <RomanNumeralsType>().OrderByDescending(x => (int)x);

            while (number > 0)
            {
                RomanNumeralsType current = romanNumbers.First(x => (number - (int)x) >= 0);
                builder.Append(current.ToString());
                number -= (int)current;
            }
            return(builder.ToString());
        }