Export (0) Print
Expand All

UInt32.ToString Method (IFormatProvider)

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)

'Declaration
Public Function ToString ( _
	provider As IFormatProvider _
) As String

Parameters

provider
Type: System.IFormatProvider

An object that supplies culture-specific formatting information.

Return Value

Type: System.String
The string representation of the value of this instance, which consists of a sequence of digits ranging from 0 to 9, without a sign or leading zeros.

Implements

IConvertible.ToString(IFormatProvider)

The ToString(IFormatProvider) method formats a UInt32 value in the default ("G", or general) format by using the NumberFormatInfo object of a specified culture. If you want to specify a different format or the current culture, use the other overloads of the ToString method, as follows:

To use format

For culture

Use the overload

Default ("G") format

Default (current) culture

ToString

A specific format

Default (current) culture

ToString(String)

A specific format

A specific culture

ToString(String, IFormatProvider)

The provider parameter is an IFormatProvider implementation. Its GetFormat method returns a NumberFormatInfo object that provides culture-specific formatting information. However, none of the properties of the NumberFormatInfo are used when formatting with the general numeric format specifier ("G").

The following example formats a 16-bit signed integer value by using several format providers, including one for the invariant culture. The output from the example illustrates that the formatted string returned by the ToString(IFormatProvider) method is the same regardless of the format provider.

Imports System.Globalization

Module Example
   Public Sub Main()
      ' Define an array of CultureInfo objects. 
      Dim ci() As CultureInfo = { New CultureInfo("en-US"), _
                                  New CultureInfo("fr-FR"), _
                                  CultureInfo.InvariantCulture } 
      Dim value As UInteger = 1870924
      Console.WriteLine("  {0,12}   {1,12}   {2,12}", _
                        GetName(ci(0)), GetName(ci(1)), GetName(ci(2))) 
      Console.WriteLine("  {0,12}   {1,12}   {2,12}", _
                        value.ToString(ci(0)), value.ToString(ci(1)), value.ToString(ci(2)))            

   End Sub 

   Private Function GetName(ci As CultureInfo) As String 
      If ci.Equals(CultureInfo.InvariantCulture) Then 
         Return "Invariant" 
      Else 
         Return ci.Name
      End If    
   End Function 
End Module 
' The example displays the following output: 
'        en-US          fr-FR      Invariant 
'      1870924        1870924        1870924

.NET Framework

Supported in: 4.5.2, 4.5.1, 4.5, 4, 3.5, 3.0, 2.0, 1.1, 1.0

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

Portable Class Library

Supported in: Portable Class Library

.NET for Windows Store apps

Supported in: Windows 8

.NET for Windows Phone apps

Supported in: Windows Phone 8.1, Windows Phone 8, Silverlight 8.1

Windows Phone 8.1, Windows Phone 8, Windows 8.1, Windows Server 2012 R2, Windows 8, Windows Server 2012, Windows 7, Windows Vista SP2, Windows Server 2008 (Server Core Role not supported), Windows Server 2008 R2 (Server Core Role supported with SP1 or later; Itanium not supported)

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

Show:
© 2014 Microsoft