Question

I have to convert string to ascii byte array.

How can I replace the following command when I don't have access to ASCII in system.text? This library is limited in mvvmcross framework.

byte[] byteArray = Encoding.ASCII.GetBytes(dataString);

I have access only to:

Encoding.UTF8
Encoding.Unicode
Encoding.BigEndianUnicode

not to

Encoding.ASCII
Était-ce utile?

La solution

Simply use

var byteArray = dataString.Select(x => (byte)x).ToArray();
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top