共用方式為


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

The return value is formatted with the general numeric format specifier ("G").

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 nulla null reference (Nothing in Visual Basic), this instance is formatted with the NumberFormatInfo object for the current culture.

Examples

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.

Dim numbers() As Short = {-23092, 0, 14894, Int16.MaxValue}
Dim providers() As CultureInfo = {New CultureInfo("en-us"), _
                                  New CultureInfo("fr-fr"), _
                                  New CultureInfo("de-de"), _
                                  New CultureInfo("es-es")}
For Each int16Value As Short In numbers
   For Each provider As CultureInfo In providers
      outputBlock.Text += String.Format("{0, 6} ({1})     ", _
                    int16Value.ToString(provider), _
                    provider.Name)
   Next
   outputBlock.Text &= vbCrLf
Next
' The example displays the following output:
'       -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)      
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)
   {
      outputBlock.Text += String.Format("{0, 6} ({1})     ",
                    int16Value.ToString(provider),
                    provider.Name);
   }
   outputBlock.Text += "\n";
}
// The example displays the following output:
//       -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)      

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.