C# Convert ToChar(Int32)
Description
Convert ToChar(Int32)
converts the value of the specified
32-bit signed integer to its equivalent Unicode character.
Syntax
Convert.ToChar(Int32)
has the following syntax.
public static char ToChar(
int value
)
Parameters
Convert.ToChar(Int32)
has the following parameters.
value
- The 32-bit signed integer to convert.
Returns
Convert.ToChar(Int32)
method returns A Unicode character that is equivalent to value.
Example
The following example converts an array of signed integers to Char values.
//w w w . j av a2 s.com
using System;
public class MainClass{
public static void Main(String[] argv){
int[] numbers = { -1, 0, 40, 160, 255, 1028,
2011, 12345, 123456, Int32.MaxValue };
char result;
foreach (int 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.