Net Framework uses Unicode UTF-16 to represent characters.
Use the system. Text. asciiencoding class to convert ASCII codes in. net. It provides getbytes () and getchars () for conversion. Of course, you can also find other useful functions in the. NET online manual.
The following is an example of conversion:
Using system;
Using system. text;
Namespace consoleapplication3
{
Class class1
{
Static void main (string [] ARGs)
{
// UTF-16 string
String mystring = "Hello World ";
Asciiencoding ae1 = new asciiencoding ();
Byte [] bytearray1 = ae1.getbytes (mystring );
// Print out the ASCII code
For (INT x = 0; x <= bytearray1.length-1; X ++)
{
Console. Write ("{0}", bytearray1 [x]);
}
Console. Write ("/N ");
// Convert the ASCII code to the corresponding character
Asciiencoding ae2 = new asciiencoding ();
Byte [] bytearray2 = {72,101,108,108,111, 111,114,108,100 };
Char [] chararray = ae2.getchars (bytearray2 );
For (INT x = 0; x <= chararray. Length-1; X ++)
{
Console. Write (chararray [x]);
}
Console. Write ("/N ");
}
}
}