How do you get a byte array out of a string in C#? I would like to pass a string to this method.
+2
A:
Try
public static byte[] StrToByteArray(string str)
{
System.Text.UTF8Encoding encoding=new System.Text.UTF8Encoding();
return encoding.GetBytes(str);
}
Thariama
2010-09-27 09:34:20
Why create a new instance of UTF8Encoding when you can use Encoding.UTF8?
Jon Skeet
2010-09-27 09:39:35
well, you are right
Thariama
2010-09-27 09:48:20