Convert String to byte array in C#

Converting a byte array to string (unicode):

byte[] b = Encoding.Unicode.GetBytes("unicode characters");
String s = Encoding.Unicode.GetString(b);

Converting a byte array to string (ascii):

byte[] b = Encoding.Unicode.GetBytes("ascii characters");
String s = Encoding.Unicode.GetString(b);
Categories: General Tags: , , , ,
%d bloggers like this: