Convert byte[] to char[] Convert byte[] to char[] arrays arrays

Convert byte[] to char[]


System.Text.Encoding.ChooseYourEncoding.GetString(bytes).ToCharArray();

Substitute the right encoding above: e.g.

System.Text.Encoding.UTF8.GetString(bytes).ToCharArray();


You must know the source encoding.

string someText = "The quick brown fox jumps over the lazy dog.";byte[] bytes = Encoding.Unicode.GetBytes(someText);char[] chars = Encoding.Unicode.GetChars(bytes);


byte[] a = new byte[50];char [] cArray= System.Text.Encoding.ASCII.GetString(a).ToCharArray();

From the URL thedixon posted

http://bytes.com/topic/c-sharp/answers/250261-byte-char

You cannot ToCharArray the byte without converting it to a string first.

To quote Jon Skeet there

There's no need for the copying here - just use Encoding.GetChars. However, there's no guarantee that ASCII is going to be the appropriate encoding to use.