Share via


Int32.ToString Method (IFormatProvider)

Microsoft Silverlight will reach end of support after October 2021. Learn more.

Converts the numeric value of this instance to its equivalent string representation using the specified culture-specific format information.

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

Syntax

'Declaration
<SecuritySafeCriticalAttribute> _
Public Function ToString ( _
    provider As IFormatProvider _
) As String
[SecuritySafeCriticalAttribute]
public string ToString(
    IFormatProvider provider
)

Parameters

Return Value

Type: System.String
The string representation of the value of this instance as specified by provider.

Implements

IConvertible.ToString(IFormatProvider)

Remarks

This instance is formatted with the general numeric format specifier ("G").

The provider parameter is an object that implements the IFormatProvider interface. Its GetFormat method returns a NumberFormatInfo object that provides culture-specific information about the format of the string that is returned by this method. The object that implements IFormatProvider can be any of the following:

If provider is null or a NumberFormatInfo object cannot be obtained from provider, the return value is formatted using the NumberFormatInfo object for the thread current culture. For information about the thread current culture, see Thread.CurrentCulture.

The .NET Framework provides extensive formatting support, which is described in greater detail in the following formatting topics:

Examples

The following example displays the string representation of an Int32 value using CultureInfo objects that represent several different cultures.

Dim value As Integer = -16325
' Display value using the invariant culture.
outputBlock.Text &= value.ToString(CultureInfo.InvariantCulture) & vbCrLf
' Display value using the en-GB culture.
outputBlock.Text &= value.ToString(New CultureInfo("en-GB")) & vbCrLf
' Display value using the de-DE culture.
outputBlock.Text &= value.ToString(New CultureInfo("de-DE")) & vbCrLf
' This example displays the following output:
'       -16325
'       -16325
'       -16325
int value = -16325;
// Display value using the invariant culture.
outputBlock.Text += value.ToString(CultureInfo.InvariantCulture) + "\n";
// Display value using the en-GB culture.
outputBlock.Text += value.ToString(new CultureInfo("en-GB")) + "\n";
// Display value using the de-DE culture.
outputBlock.Text += value.ToString(new CultureInfo("de-DE")) + "\n";
// This example displays the following output:
//       -16325
//       -16325
//       -16325

Version Information

Silverlight

Supported in: 5, 4, 3

Silverlight for Windows Phone

Supported in: Windows Phone OS 7.1, Windows Phone OS 7.0

XNA Framework

Supported in: Xbox 360, Windows Phone OS 7.0

Platforms

For a list of the operating systems and browsers that are supported by Silverlight, see Supported Operating Systems and Browsers.