C# does not seem to have a system function specifically used to convert ASCII characters to characters or characters to ASCII codes, so the editor will borrow the cast type conversion here to realize the mutual conversion between ASCII codes and characters.
The so-called ASCII code, that is, American Standard Code for Information Interchange, is abbreviation of the American Information Exchange standard code. It is a Latin letter-based encoding system and is also the most common single-byte encoding system at present. This article tells how to convert characters such as letters or numbers into ASCII encoding in C#, and can also convert ASCII encoding into characters.
1. Convert characters to ASCII code (number)
int asc = (int)'a'; // Convert the character directly to int type to get the ASCII code value
(()); // Convert numbers to strings and transfer them out
2. Convert ASCII code (number) to characters
string alpha = ((char)65).ToString(); // Convert the number directly to char type to get the characters corresponding to the ASCII code
(alpha); // Output string
The editor has taken a clue here, because C# does not seem to have a system function specifically used to convert ASCII characters or characters to ASCII characters, so I will borrow the cast type conversion here, and the effect is obvious!
In addition, I saw a book that says that you can use the following method to obtain the ASCII code:
You can try it, it's nonsense! GetBytes returns an array, and using ToString() on an array will get "[]", which is the type of the array.
Of course, if you add a [0] after GetBytes and index its first element, you can get the correct value. Use as follows: