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#?
Java 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
}