Format Method

[This documentation is for preview only, and is subject to change in later releases. Blank topics are included as placeholders.]

Converts the value of a specified object to an equivalent string representation using specified format and culture-specific formatting information.

Namespace:  System
Assembly:  mscorlib (in mscorlib.dll)

string Format(
	string format,
	Object arg,
	IFormatProvider formatProvider


Type: System..::..String
A format string containing formatting specifications.
Type: System..::..Object
An object to format.
Type: System..::..IFormatProvider
An object that supplies format information about the current instance.

Return Value

Type: System..::..String
The string representation of the value of arg, formatted as specified by format and formatProvider.

ICustomFormatter..::..Format is a callback method. It is called by a method that supports custom formatting, such as String.Format(IFormatProvider, String, array<Object>[]()[][]). The implementation is called once for each format item in a composite format string.

The arg parameter is the object in the object list whose zero-based position corresponds to the index of a particular format item.

The format parameter contains a format string, which is the formatString component of a format item. If the format item has no formatString component, the value of format is nullNothingnullptrunita null reference (Nothing in Visual Basic). If format is nullNothingnullptrunita null reference (Nothing in Visual Basic), depending on the type of arg, you may be able to use the default format specification of your choice.

The formatProvider parameter is the IFormatProvider implementation that provides formatting for arg. Typically, it is an instance of your ICustomFormatter implementation. If formatProvider is nullNothingnullptrunita null reference (Nothing in Visual Basic), ignore that parameter.

Your implementation of the Format method must include the following functionality so the .NET Framework can provide formatting you do not support. If your format method does not support a format, determine whether the object being formatted implements the IFormattable interface. If it does, invoke the IFormattable..::..ToString method of that interface. Otherwise, invoke the default Object..::..ToString method of the underlying object. The following code illustrates this pattern.