Export (0) Print
Expand All

Int16.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)

public string ToString(
	IFormatProvider provider
)

Parameters

provider
Type: System.IFormatProvider

An IFormatProvider that supplies culture-specific formatting information.

Return Value

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

Implements

IConvertible.ToString(IFormatProvider)

The ToString(IFormatProvider) method formats an Int16 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 .NET Framework provides extensive formatting support, which is described in greater detail in the following formatting topics:

The provider parameter is an IFormatProvider implementation whose IFormatProvider.GetFormat method returns a NumberFormatInfo object. Typically, provider is a NumberFormatInfo object or a CultureInfo object. The NumberFormatInfo object provides culture-specific information about the format of the string returned by this method. If provider is null, this instance is formatted with the NumberFormatInfo object for the current culture.

The following example iterates an array of Int16 values and displays each of them to the console by calling the Int16.ToString(IFormatProvider) method with different format providers. Because of the simple formatting defined by the default "G" format specifier, the formatted strings produced for each Int16 value are identical regardless of the value of the provider parameter.

short[] numbers = {-23092, 0, 14894, Int16.MaxValue};
CultureInfo[] providers = {new CultureInfo("en-us"), 
                           new CultureInfo("fr-fr"), 
                           new CultureInfo("de-de"), 
                           new CultureInfo("es-es")};
foreach (Int16 int16Value in numbers)
{
   foreach (CultureInfo provider in providers)
   {
      Console.Write("{0, 6} ({1})     ", 
                    int16Value.ToString(provider), 
                    provider.Name);
   }
   Console.WriteLine();
}
// The example displays the following output to the console: 
//       -23092 (en-US)     -23092 (fr-FR)     -23092 (de-DE)     -23092 (es-ES) 
//            0 (en-US)          0 (fr-FR)          0 (de-DE)          0 (es-ES) 
//        14894 (en-US)      14894 (fr-FR)      14894 (de-DE)      14894 (es-ES) 
//        32767 (en-US)      32767 (fr-FR)      32767 (de-DE)      32767 (es-ES)      

.NET Framework

Supported in: 4.6, 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

Supported in: Windows Phone 8.1

Supported in: Windows Phone Silverlight 8.1

Supported in: Windows Phone Silverlight 8

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