how do convert string to byte[] in C#

前端 未结 4 2183
长情又很酷
长情又很酷 2020-12-20 16:07

How do you get a byte array out of a string in C#? I would like to pass a string to this method.

4条回答
  •  甜味超标
    2020-12-20 16:36

    Try

    public static byte[] StrToByteArray(string str)
    {
        System.Text.UTF8Encoding  encoding=new System.Text.UTF8Encoding();
        return encoding.GetBytes(str);
    }
    

提交回复
热议问题