C# Convert ToString(Int16, IFormatProvider)

Description

Convert ToString(Int16, IFormatProvider) converts the value of the specified 16-bit signed integer to its equivalent string representation, using the specified culture-specific formatting information.

Syntax

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


public static string ToString(
  short value,
  IFormatProvider provider
)

Parameters

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

  • value - The 16-bit signed integer to convert.
  • provider - An object that supplies culture-specific formatting information.

Returns

Convert.ToString(Int16, IFormatProvider) method returns The string representation of value.

Example

The following example defines a custom NumberFormatInfo class that defines its negative sign as the string "~" and its positive sign as the string "!".


/*from   ww  w.  j a va2 s. c o m*/
using System;
public class MainClass{
  public static void Main(String[] argv){  
    short[] numbers = { Int16.MinValue, Int16.MaxValue};
    System.Globalization.NumberFormatInfo nfi = new System.Globalization.NumberFormatInfo();
    nfi.NegativeSign = "~";
    nfi.PositiveSign = "!";
    
    foreach (short number in numbers)
       Console.WriteLine("{0,-8}  -->  {1,8}", 
                         Convert.ToString(number, System.Globalization.CultureInfo.InvariantCulture), 
                         Convert.ToString(number, nfi));
  }
}
    

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