C# Convert ToChar(Int16)

Description

Convert ToChar(Int16) converts the value of the specified 16-bit signed integer to its equivalent Unicode character.

Syntax

Convert.ToChar(Int16) has the following syntax.


public static char ToChar(
  short value
)

Parameters

Convert.ToChar(Int16) has the following parameters.

  • value - The 16-bit signed integer to convert.

Returns

Convert.ToChar(Int16) method returns A Unicode character that is equivalent to value.

Example

The following example converts an array of signed 16-bit integers to Char values.


/*w  w w  .j  av  a 2  s. co  m*/
using System;
public class MainClass{
  public static void Main(String[] argv){  
    short[] numbers = { Int16.MinValue, 0, 40, 160, 255, 1028, 
                        2011, Int16.MaxValue };
    char result;
    foreach (short number in numbers)
    {
       try {
          result = Convert.ToChar(number);
          Console.WriteLine("{0} converts to '{1}'.", number, result);
       }   
       catch (OverflowException) {
          Console.WriteLine("{0} is outside the range of the Char data type.", 
                            number);
       }
    }   
  }
}
    

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