This documentation is archived and is not being maintained.

ICustomFormatter.Format Method

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
String Format (
	String format, 
	Object arg, 
	IFormatProvider formatProvider
function Format (
	format : String, 
	arg : Object, 
	formatProvider : IFormatProvider
) : String
Not applicable.



A format string containing formatting specifications.


An object to format.


An IFormatProvider object that supplies format information about the current instance.

Return Value

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

The format parameter contains a user-defined formatting specification. For more information about standard .NET Framework formatting specifications, see [<topic://cpConFormattingOverview>].

If format is a null reference (Nothing in Visual Basic), use the default format specification of your choice. If formatProvider is 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.

Here is a fragment of C# code that demonstrates this pattern for object arg, format format, format provider formatProvider, and return value, s.

if (arg is IFormattable) s = ((IFormattable)arg).ToString(format, formatProvider);
else if (arg != null) s = arg.ToString();

Windows 98, Windows Server 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile for Pocket PC, Windows Mobile for Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

The Microsoft .NET Framework 3.0 is supported on Windows Vista, Microsoft Windows XP SP2, and Windows Server 2003 SP1.

.NET Framework

Supported in: 3.0, 2.0, 1.1, 1.0

.NET Compact Framework

Supported in: 2.0, 1.0

XNA Framework

Supported in: 1.0