Share via


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)

Syntax

'Declaration
Function Format ( _
    format As String, _
    arg As Object, _
    formatProvider As IFormatProvider _
) As String
string Format(
    string format,
    Object arg,
    IFormatProvider formatProvider
)
String^ Format(
    String^ format, 
    Object^ arg, 
    IFormatProvider^ formatProvider
)
abstract Format : 
        format:string * 
        arg:Object * 
        formatProvider:IFormatProvider -> string 
function Format(
    format : String, 
    arg : Object, 
    formatProvider : IFormatProvider
) : String

Parameters

Return Value

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

Remarks

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 null Nothing nullptr unit a null reference (Nothing in Visual Basic) . If format is null Nothing nullptr unit a 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 null Nothing nullptr unit a 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.

.NET Framework Security

See Also

Reference

ICustomFormatter Interface

System Namespace