Console.WriteLine (Convert.ToChar(2)); | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

Console.WriteLine (Convert.ToChar(2));

The output is wired, could someone help me, please

18th Jun 2020, 2:08 PM
Zhengrong Yan
Zhengrong Yan - avatar
5 Answers
+ 3
The Convert.ToChar method converts the ASCII code given as argument to char and not the argument itself. For example, if you wanted to convert "A" to char, you will write Convert.ToChar(65), as the ASCII code of A is 65. In the same way, if you wanted to convert 2 to char, you will write Convert.ToChar(49) as the ASCII value for '2' is 49. Here is a list of all the ASCII values https://theasciicode.com.ar/
18th Jun 2020, 2:26 PM
XXX
XXX - avatar
+ 1
What have you done so far? Show your code progress.
18th Jun 2020, 2:14 PM
James Clark I. Vinarao
James Clark I. Vinarao - avatar
+ 1
ASCII character 2 is the non-printable character STX (start of text) and the equivalent of CTRL-B.
18th Jun 2020, 9:29 PM
Brian
Brian - avatar
+ 1
David Yan no. The ASCII values only apply for chars. The char you use in any programming language, are actually these values inside. The other Convert.To don't use ASCII values. You can easily convert a string to int by Convert.ToInt32("1234").
19th Jun 2020, 4:49 AM
XXX
XXX - avatar
0
XXX ,do all Convert.To method converts the ASCII code?
18th Jun 2020, 9:31 PM
Zhengrong Yan
Zhengrong Yan - avatar