Example

using System;
using System.Text;

namespace Samples
{
  public class UTF8EncodingSample
  {
    public static void Main()
    {
      UTF8Encoding u = (UTF8Encoding) Encoding.UTF8;
      string s = "Pi is (\u03a0)";
      Byte[] bytes = u.GetBytes(s);
      foreach(Int16 i in bytes)
        Console.Write("{0}, ", i);
      Console.WriteLine();
      int count = u.GetCharCount(bytes, 0,
                            bytes.Length);
      char[] chars = new char[count];
      u.GetChars(bytes, 0, bytes.Length, chars, 0);
      foreach(Int16 i in chars)
        Console.Write("{0}, ", i);
      Console.WriteLine();
    }
  }
}
The output is
80, 105, 32, 105, 115, 32, 40, 206, 160, 41,
80, 105, 32, 105, 115, 32, 40, 928, 41,

Get .NET Framework Standard Library Annotated Reference, Volume 1: Base Class Library and Extended Numerics Library now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.