C# Int16 ToString(String)

Description

Int16 ToString(String) converts the numeric value of this instance to its equivalent string representation, using the specified format.

Syntax

Int16.ToString(String) has the following syntax.


public string ToString(
  string format
)

Parameters

Int16.ToString(String) has the following parameters.

  • format - A numeric format string.

Returns

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

Example

The following example initializes two Int16 values and displays them to the console using each of the supported standard format strings and several custom format strings.


//from   w ww .j  ava2  s .c o  m
using System;
public class MainClass{
  public static void Main(String[] argv){  
    Int16[] values = {-12345, 12};
    string[] formats = {"C4", "D6", "e1", "E2", "F1", "G", "N1", 
                        "P0", "X4", "000000.0000", "##000.0"};
    foreach (string format in formats)
    {
       Console.WriteLine("'{0,2}' format specifier: {1,17}   {2,17}",  
                         format, 
                         values[0].ToString(format), 
                         values[1].ToString(format));
    }                                                               
  }
}

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