Convert string to byte []

How to convert string to byte [] in C #?

+4
source share
2 answers

Note that .NET strings are encoded as Unicode (UTF-16):

byte[] bytes = Encoding.Unicode.GetBytes("a string"); 
+6
source

using byte[] data = Encoding.UTF8.GetBytes(myString);

+6
source

Source: https://habr.com/ru/post/1348010/


All Articles