Windows apps
Collapse the table of content
Expand the table of content
Information
The topic you requested is included in another documentation set. For convenience, it's displayed below. Choose Switch to see the topic in its original location.

Convert::ToString Method (Object^, IFormatProvider^)

 

Converts the value of the specified object to its equivalent string representation using the specified culture-specific formatting information.

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

public:
static String^ ToString(
	Object^ value,
	IFormatProvider^ provider
)

Parameters

value
Type: System::Object^

An object that supplies the value to convert, or null.

provider
Type: System::IFormatProvider^

An object that supplies culture-specific formatting information.

Return Value

Type: System::String^

The string representation of value, or String::Empty if value is an object whose value is null. If value is null, the method returns null.

If the value parameter implements the IConvertible interface, the method calls the IConvertible::ToString(IFormatProvider^)implementation of value. Otherwise, if the value parameter implements the IFormattable interface, the method calls its IFormattable::ToString(String^, IFormatProvider^)implementation. If value implements neither interface, the method calls the value parameter's ToString() method, and the provider parameter is ignored.

The provider parameter is used if the value parameter implements the IConvertible or IFormattable interface. The most common use of the provider parameter is to specify culture-specific information used in the conversion of value. For example, if the value parameter is a negative decimal number, the provider parameter can supply culture-specific information about the notation used for the negative sign and decimal separator. The second example in the next section illustrates a format provider that does not supply culture-sensitive formatting information.

The following example defines a Temperature class that overrides the Object::ToString method but does not implement the IConvertible interface. The example illustrates how calls to the Convert::ToString(Object^, IFormatProvider^) method, in turn, call the Temperature.ToString method.

No code example is currently available or this language may not be supported.

The following example defines a Temperature class that implements the IFormattable interface but does not implement the IConvertible interface. Its IFormattable::ToStringimplementation represents the Temperature value in Celsius, Fahrenheit, or Kelvin, depending on the format string. The example also defines a TemperatureProvider class that implements IFormatProvider and provides a randomly generated format string that is used by the IFormattable implementation of the Temperature class.

No code example is currently available or this language may not be supported.

Universal Windows Platform
Available since 8
.NET Framework
Available since 1.1
Portable Class Library
Supported in: portable .NET platforms
Silverlight
Available since 2.0
Windows Phone Silverlight
Available since 7.0
Windows Phone
Available since 8.1
Return to top
Show:
© 2017 Microsoft