public static void Main()
var numbers = new[] { 123, 1, 2, 3, 9, 3999, 1000, 2000, 2500, 2023 };
foreach(var number in numbers)
Console.WriteLine($"{number,4} ==> {number.AsRoman()}");
public static class Numbers
private static readonly string[] _1000 = {"", "M", "MM", "MMM"};
private static readonly string[] _100 = {"", "C", "CC", "CCC", "CD", "D", "DC", "DCC", "DCCC", "CM"};
private static readonly string[] _10 = {"", "X", "XX", "XXX", "XL", "L", "LX", "LXX", "LXXX", "XC"};
private static readonly string[] _1 = {"", "I", "II", "III", "IV", "V", "VI", "VII", "VIII", "IX"};
public static string AsRoman(this int number)
if (number < 0 || number >= 4000)
throw new ArgumentException(nameof(number), $"{number} must be in the range of 0 < n < 4000.");
return $"{_1000[number / 1000]}{_100[(number % 1000) / 100]}{_10[(number % 100) / 10]}{_1[number % 10]}";