Reputation: 35647
How do you get a byte array out of a string in C#? I would like to pass a string to this method.
Upvotes: 8
Views: 2570
Reputation: 50840
Try
public static byte[] StrToByteArray(string str)
{
System.Text.UTF8Encoding encoding=new System.Text.UTF8Encoding();
return encoding.GetBytes(str);
}
Upvotes: 2