using System.Collections.Generic;
public static class Program
public static void Main()
Console.WriteLine(312.ToRoman());
public static class Extensions
public static string ToRoman(this int number)
var romanMap = new Dictionary<string, int>
{"M", 1000}, {"CM", 900}, {"D", 500}, {"CD", 400}, {"C", 100}, {"XC", 90}, {"L", 50}, {"XL", 40}, {"X", 10}, {"IX", 9}, {"V", 5}, {"IV", 4}, {"I", 1}
if ((number < 0) || (number > 3999))
throw new ArgumentOutOfRangeException("insert value betwheen 1 and 3999");
foreach (var pair in romanMap.Where(pair => number >= pair.Value))
return pair.Key + ToRoman(number - pair.Value);
throw new ArgumentOutOfRangeException("something bad happened");