Reputation: 35627
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: 2552
Reputation: 50832
Try
public static byte[] StrToByteArray(string str)
{
System.Text.UTF8Encoding encoding=new System.Text.UTF8Encoding();
return encoding.GetBytes(str);
}
Upvotes: 2