how do convert string to byte[] in C#

前端 未结 4 2172
长情又很酷
长情又很酷 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:16
    Encoding.UTF8.GetBytes("abcd");
    
    0 讨论(0)
  • 2020-12-20 16:26

    Encoding.GetBytes method.

    0 讨论(0)
  • 2020-12-20 16:32

    Use GetBytes( )

    0 讨论(0)
  • 2020-12-20 16:36

    Try

    public static byte[] StrToByteArray(string str)
    {
        System.Text.UTF8Encoding  encoding=new System.Text.UTF8Encoding();
        return encoding.GetBytes(str);
    }
    
    0 讨论(0)
提交回复
热议问题