Use UnicodeEncoding to encode and decode char array : Encoding Unicode « I18N Internationalization « C# / CSharp Tutorial






using System;
using System.Text;

public class MainClass{
   public static void Main()  {
      UnicodeEncoding u16 = new UnicodeEncoding( false, true, true );
      Encoder myEncoder = u16.GetEncoder();
      Decoder myDecoder = u16.GetDecoder();

      char[] myChars = new char[5] { 'z', 'a', '\u0306', '\u01FD', '\u03B2' };
      Console.WriteLine( myChars );

      int iBC  = myEncoder.GetByteCount( myChars, 0, myChars.Length, true );
      byte[] myBytes = new byte[iBC];
      myEncoder.GetBytes( myChars, 0, myChars.Length, myBytes, 0, true );

      for ( int i = 0; i < myBytes.Length; i++ ){
         Console.WriteLine( "{0:X2} ", myBytes[i] );
      } 
 
      int iCC  = myDecoder.GetCharCount( myBytes, 0, myBytes.Length, true );
      char[] myDecodedChars = new char[iCC];
      myDecoder.GetChars( myBytes, 0, myBytes.Length, myDecodedChars, 0, true );
      Console.WriteLine( myDecodedChars );

   }

}








21.12.Encoding Unicode
21.12.1.Unicode encode
21.12.2.Big Endian Unicode Bytes
21.12.3.Convert UTF8 from Unicode
21.12.4.Encodings: Encoding.GetEncoding(1252)
21.12.5.Use UnicodeEncoding to encode and decode char array