public interface IFormattable
|
A format describes the appearance of an object when it is converted to a string. A format can be either standard or custom. A standard format takes the form Axx, where A is an alphabetic character called the format specifier, and xx is a non-negative integer called the precision specifier. The format specifier controls the type of formatting applied to the value being represented as a string. The precision specifier controls the number of significant digits or decimal places in the string, if applicable.
When a format includes symbols that vary by culture, such as the currency symbol represented by the "C" and "c" formats, a formatting object supplies the actual characters used in the string representation. A method might include a parameter to pass an IFormatProvider object that supplies a formatting object, or the method might use the default formatting object, which contains the symbol definitions for the current thread. The current thread typically uses the same set of symbols used system-wide by default.
Classes that require more control over the formatting of strings than Object.ToString provides should implement IFormattable, whose IFormattable.ToString method uses the current thread's Thread.CurrentCulture property.
A class that implements IFormattable must support the "G" (general) formatting code. Besides the "G" code, the class can define the list of formatting codes that it supports.
For more information on formatting and formatting codes, see the conceptual topic at MSDN: formattingoverview.
ToString | Formats the value of the current instance using the specified format. |
string ToString( |
format
-or-
null to use the default format defined for the type of the IFormattable implementation.
The String specifying the format to use.-or-
null to use the default format defined for the type of the IFormattable implementation.
formatProvider
-or-
null to obtain the numeric format information from the current locale setting of the operating system.
The IFormatProvider to use to format the value.-or-
null to obtain the numeric format information from the current locale setting of the operating system.
NumberFormatInfo supplies numeric formatting information, such as the characters to use for decimal and thousand separators and the spelling and placement of currency symbols in monetary values.
DateTimeFormatInfo supplies date- and time-related formatting information, such as the position of the month, the day and the year in a date pattern.
CultureInfo contains the default formatting information in a specific culture, including the numeric format information and date- and time-related formatting information.