Skip to content
Daniel Gonzalez Garcia edited this page May 5, 2017 · 3 revisions

Roman Numerals

RomanNumeral is, probably, what is going to be used most of the time.

From arabic to roman numeral

var thirty = new RomanNumeral(30);
ReadOnlyCollection<RomanFigure> xxx = thirty.Figures;
string XXX = thirty.ToString();

Getting an instance from a shortcut

RomanNumeral zero = RomanNumeral.Zero;

Parsing a roman representation

RomanNumeral nineteenTwentyEight = RomanNumeral.Parse("MCMXXVIII");
bool _true = RomanNumeral.TryParse("MCMXXVIII", out nineteenTwentyEight);
ushort _1928 = nineteenTwentyEight.Value;

Comparisons

int lessThanZero = thirty.CompareTo(nineteenTwentyEight);
_true = thirty < nineteenTwentyEight;
_true = nineteenTwentyEight >= thirty;

bool _false = nineteenTwentyEight.Equals(thirty);
_false = thirty == nineteenTwentyEight;

Castings

_1928 = (ushort) nineteenTwentyEight;
XXX = (string) thirty;

Arithmetic operations

RomanNumeral sixty = thirty.Plus(thirty);
thirty = sixty.Minus(thirty);

sixty = thirty + thirty;
thirty = sixty - thirty;

Roman Figures

RomanFigure might not be the most used type for SharpRomans, but it is a pretty complete numeric type.

Getting an instance from a shortcut

RomanFigure fromAccesor = RomanFigure.L;

Parsing and converting instances

// parse a char
RomanFigure ten = RomanFigure.Parse('X');
bool _true = RomanFigure.TryParse('X', out ten);
			
// parse a string
RomanFigure five = RomanFigure.Parse("V");
_true = RomanFigure.TryParse("V", out five);

// convert a number
var one = RomanFigure.Convert(1);
RomanFigure.TryConvert(1, out one);

Getting information

ushort _5 = five.Value;
char V = five.Literal;
string quinque = five.Name;

Comparisons

int lessThanZero = five.CompareTo(ten);
_true = five < ten;
_true = five >= one;

bool _false = five.Equals(ten);
_false = ten == five;

Castings

_5 = (ushort) five;
V = (char) five;		

Clone this wiki locally