Convertir byte en char

Comment convertir un tableau d’ byte en un tableau de caractères en C #?

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

Remplacez le bon encodage ci-dessus: par exemple

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

Vous devez connaître l’encodage source.

 ssortingng 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.GetSsortingng(a).ToCharArray(); 

De l’URL thedixon a posté

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

Vous ne pouvez pas ToCharArray l’octet sans le convertir d’abord en chaîne.

Pour citer Jon Skeet il y a

Il n’y a pas besoin de copier ici – utilisez simplement Encoding.GetChars. Cependant, il n’y a aucune garantie que le codage ASCII soit approprié.