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



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 Formatting Overview.

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 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 .NET Framework does not support all versions of every platform. For a list of the supported versions, see System Requirements.

.NET Framework

Supported in: 2.0, 1.1, 1.0

.NET Compact Framework

Supported in: 2.0, 1.0

Community Additions