I wanted to print an integer in Roman numerals and meet this answer from Jesse Slicer. This is an extension method, but I was interested to use ToString(string, IFormatProvider)to do something like
int a = 10;
string b = a.ToString("RN", provider);
string c = string.Format(provider, "{0:RN} blah foo", a);
instead
int a = 10;
string b = a.ParseRomanNumeral();
string c = string.Format("{0} blah foo", a.ParseRomanNumeral());
I have never written a format provider, so I'm not sure about the work, but here is my question. For some correct format conversion, such as Roman numerals, you would use:
- format provider
- use extension method
- write a class RomanNumeral that implements
Parse, TryParseandToString - something else
and why?
string.Format() (, StringBuilder.AppendFormat()) ? , .
, , . , ( ).