using System.Security.Cryptography;
public static void Main()
Decoder utf8Decoder = Encoding.UTF8.GetDecoder();
byte[] bytes1 = { 0x20, 0x23, 0xe2 };
byte[] bytes2 = { 0x98, 0xa3 };
char[] chars = new char[3];
int charLen = utf8Decoder.GetChars(bytes1, 0, bytes1.Length, chars, 0);
charLen += utf8Decoder.GetChars(bytes2, 0, bytes2.Length, chars, charLen);
foreach(char c in chars) { Console.WriteLine("[{0}] = U+{1:X4}", c, (ushort)c); }
Byte[] bytes3 = new Byte[] { 99, 204, 128, 234, 130, 160 };
int charCount = utf8Decoder.GetCharCount(bytes3, 0, bytes3.Length);
chars = new Char[charCount];
int charsDecodedCount = utf8Decoder.GetChars(bytes3, 0, bytes3.Length, chars, 0);
Console.WriteLine("{0} characters used to decode bytes.", charsDecodedCount);
Console.Write("Decoded chars: ");
foreach (Char c in chars) { Console.Write("[{0}]", c); }