How do you convert a string to a byte array in .NET?

前端 未结 4 1201
陌清茗
陌清茗 2020-12-08 01:30

I have a string that I need to convert to the equivalent array of bytes in .NET.

This ought to be easy, but I am having a brain cramp.

4条回答
  •  北荒
    北荒 (楼主)
    2020-12-08 02:23

    Like this:

        string test = "text";
        byte[] arr = Encoding.UTF8.GetBytes(test);
    

提交回复
热议问题