Convert.ToChar
eventually performs an explicit conversion as (char)value
, where value is your int
value. Before doing so, it checks to ensure value is in the range 0 to 0xffff
, and throws an OverflowException
if it is not. The extra method call, value/boundary checks, and OverflowException
may be useful, but if not, the performance will be better if you just use (char)value
.
This will make sure everything is ok while converting but take some time while making sure of that,
convertingchar = Convert.ToChar(intvalue);
This will convert it without making sure everything is ok so less time,
convertingchar = (char)intvalue;
For example.
Console.WriteLine("(char)122 is {0}", (char)122);
yields:
(char)122 is z
NOTE
Not related to question directly but if you feel that Conversion is slow then you might be doing something wrong. The question is why do you need to convert the lot of the int
to char
. What you are trying to achieve. There might be better way.