System.IFormattable Interface

Assembly: Mscorlib.dll
Namespace: System
Summary
Provides functionality to format the value of an object into a string representation.
C# Syntax:
public interface IFormattable
Remarks
IFormattable is implemented by the base data types.

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.



Notes to implementors:

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.

See also:
System Namespace See also:
MSDN: formattingoverview | IFormatProvider | Object.ToString | Thread.CurrentCulture

System.IFormattable Member List:

Public Methods
ToString Formats the value of the current instance using the specified format.

System.IFormattable Member Details

Method: ToString(
   string format,
   IFormatProvider formatProvider
)
Summary
Formats the value of the current instance using the specified format.
C# Syntax:
string ToString(
   string format,
   IFormatProvider formatProvider
);
Parameters:

format

The String specifying the format to use.

-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

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.

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.

Return Value:
A String containing the value of the current instance in the specified format.
Remarks
NumberFormatInfo, DateTimeFormatInfo and CultureInfo implement the IFormatProvider interface.

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.

See also:
String | IFormatProvider | NumberFormatInfo | DateTimeFormatInfo | CultureInfo

Return to top


Top of page

Copyright (c) 2002 Microsoft Corporation. All rights reserved.