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
Was it helpful?

Solution

Simply use

var byteArray = dataString.Select(x => (byte)x).ToArray();
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top