title: How to convert char[] to UTF-8 byte[] in C#?
body: <p>I'm porting a Java function as below codes to C#, it converts a char array to UTF-8 format, and then convert to byte array, how can do this in .Net platform via C#?</p>
  
  <p>Java code:</p>
  
  <pre><code>public static byte[] GetBytes(char[] chars) 
  {
      Charset cs = Charset.forName("UTF-8");
      CharBuffer cb = CharBuffer.allocate(chars.length);
      cb.put(chars);
      cb.flip();
      ByteBuffer bb = cs.encode(cb);
      byte[] array = bb.array();
  
      return array
  }
  </code></pre>