If I specifiy a FormatString property for some databound value of {0:00000}, where I want a number to always have five digits, padded with '0' where necessary, what method on what class is actually invoked to perform the formatting and return the formatted string?
A:
It is the formatted object itself, its class has to implement IFormattable
public interface IFormattable
{
string ToString(string format, IFormatProvider formatProvider);
}
And so any type, like struct Int32 can do its own formatting. In absence of the interface Format() defaults to the normal ToString().
Henk Holterman
2010-08-13 14:23:25
Aha, pity class String does not implement that interface. I would have liked to experiment with some numeric formats on strings that are numeric.
ProfK
2010-08-15 14:49:47