C# Int16 ToString(String, IFormatProvider)

Description

Int16 ToString(String, IFormatProvider) converts the numeric value of this instance to its equivalent string representation using the specified format and culture-specific formatting information.

Syntax

Int16.ToString(String, IFormatProvider) has the following syntax.


public string ToString(
  string format,
  IFormatProvider provider
)

Parameters

Int16.ToString(String, IFormatProvider) has the following parameters.

  • format - A numeric format string.
  • provider - An object that supplies culture-specific formatting information.

Returns

Int16.ToString(String, IFormatProvider) method returns The string representation of the value of this instance as specified by format and provider.

Example

The following example displays an Int16 value using each of the supported standard format strings in four different cultures.


using System.Globalization;
using System;//  w ww .j  a v a2  s  .  com
public class MainClass{
  public static void Main(String[] argv){  
    Int16 value = 12345;
    string[] formats = {"C", "D6", "e1", "E2", "F1", "G", "N1", 
                        "P0", "X4", "000000.0000", "##000.0"};
    CultureInfo[] providers = {new CultureInfo("en-us"), 
                               new CultureInfo("fr-fr"), 
                               new CultureInfo("de-de"), 
                               new CultureInfo("es-es")};
    // Display header.
    Console.WriteLine("{0,24}{1,14}{2,14}{3,14}", providers[0], providers[1], 
                      providers[2], providers[3]);
    Console.WriteLine();
    // Display a value using each format string. 
    foreach (string format in formats)
    {
       // Display the value for each provider on the same line.
       Console.Write("{0,-12}", format);
       foreach (CultureInfo provider in providers)
       {
          Console.Write("{0,12}  ", 
                        value.ToString(format, provider)); 
       }
       Console.WriteLine();
    }
  }
}
    

The code above generates the following result.





















Home »
  C# Tutorial »
    System »




Array
BitConverter
Boolean
Byte
Char
Console
ConsoleKeyInfo
Convert
DateTime
DateTimeOffset
Decimal
Double
Enum
Environment
Exception
Guid
Int16
Int32
Int64
Math
OperatingSystem
Random
SByte
Single
String
StringComparer
TimeSpan
TimeZone
TimeZoneInfo
Tuple
Tuple
Tuple
Type
UInt16
UInt32
UInt64
Uri
Version