BCL mscorlib [00 00 00 00 00 00 00 00 04 00 00 00 00 00 00 00 ] 1.0.5000.0 2.0.0.0 4.0.0.0 System.Runtime.InteropServices.ComVisible(true)

The interface converts an object to its string representation based on a format string and a format provider.

A format string typically defines the general appearance of an object. For example, the .NET Framework supports the following:

Standard format strings for formatting enumeration values (see Enumeration Format Strings).

Standard and custom format strings for formatting numeric values (see Standard Numeric Format Strings and Custom Numeric Format Strings).

Standard and custom format strings for formatting date and time values (see Standard Date and Time Format Strings and Custom Date and Time Format Strings).

Standard and custom format strings for formatting time intervals (see Standard TimeSpan Format Strings and Custom TimeSpan Format Strings).

You can also define your own format strings to support formatting of your application-defined types.

A format provider returns a formatting object that typically defines the symbols used in converting an object to its string representation. For example, when you convert a number to a currency value, a format provider defines the currency symbol that appears in the result string. The .NET Framework defines three format providers:

The class, which returns either a object for formatting numeric values, or a object for formatting date and time values.

The class, which returns an instance of itself for formatting numeric values.

The class, which returns an instance of itself for formatting date and time values.

In addition, you can define your own custom format providers to supply culture-specific, profession-specific, or industry-specific information used in formatting. For more information about implementing custom formatting by using a custom format provider, see .

The interface defines a single method, , that supplies formatting services for the implementing type. The method can be called directly. In addition, it is called automatically by the and methods, and by methods that use the composite formatting feature in the .NET Framework. Such methods include , , and , among others. The method is called for each format item in the method's format string.

The interface is implemented by the base data types.

Provides functionality to format the value of an object into a string representation.

- Method
  1.0.5000.0
  2.0.0.0
  4.0.0.0
  System.String `` `` The specified is invalid or cannot be used with the type of the current instance.

  The following example demonstrates using the method to display values in a variety of formats. The current system culture is U.S. English, which provides the default values for the parameter of .

  `using System; class FormattableExample { public static void Main() { double d = 123.12345678901234; string[] formats = {"C","E","e","F","G","N","P","R"}; for (int i = 0; i< formats.Length;i++) Console.WriteLine("{0:R} as {1}: {2}",d,formats[i],d.ToString(formats[i],null)); string[]intFormats = {"D","x","X"}; int val = 255; for (int i = 0; i< intFormats.Length;i++) Console.WriteLine("{0} as {1}: {2}",val,intFormats[i],val.ToString(intFormats[i],null)); } }`

  The output is

  123.12345678901234 as C: $123.12

  123.12345678901234 as E: 1.231235E+002

  123.12345678901234 as e: 1.231235e+002

  123.12345678901234 as F: 123.12

  123.12345678901234 as G: 123.123456789012

  123.12345678901234 as N: 123.12

  123.12345678901234 as P: 12,312.35 %

  123.12345678901234 as R: 123.12345678901234

  255 as D: 255

  255 as x: ff

  255 as X: FF

  The method converts a value to a string representation that can be expressed in multiple ways. Its precise format depends on specific symbols or a specified order defined by specific cultures, professions, or industries. You can call the method directly. It is also called automatically by the and methods, and by methods that use the composite formatting feature in the .NET Framework, such as , , and . (For more information, see Composite Formatting.)

  Composite formatting methods call the method once for each format item in a format string. The parameters passed to the method depend on the specific formatting method that is called and on the content of the format item, as follows:

  If the format item does not include a format string (for example, if the format item is simply {0}), it is passed null as the value of the parameter.

  If the format item includes a format string (for example, {0:G}), that format string is passed as the value of the parameter.

  If the original method call does not include an parameter, is passed as the value of the parameter.

  If the original method call includes an parameter, the provider that is supplied in the method call is passed as the value of the parameter.

  An object's implementation is called by composite formatting methods only if they are not passed an format provider, or if the method of the custom format provider returns null.

  The .NET Framework includes three format providers, all of which implement the interface:

  supplies numeric formatting information, such as the characters to use for decimal and group separators, and the spelling and placement of currency symbols in monetary values.

  supplies date-related and time-related formatting information, such as the position of the month, the day, and the year in a date pattern.

  contains the default formatting information in a specific culture, including the numeric format information, and date-related and time-related formatting information.

  In addition, you can define your own custom format provider.

  Formats the value of the current instance using the specified format.

  The value of the current instance in the specified format.

  The format to use. The provider to use to format the value. 0
0