using System;
using System.Text;
class Program
{
static void Main()
{
// 定义一个字符串
string str = "Hello, World!";
// 使用 UTF-8 编码将字符串转换为 byte 数组
byte[] bytes = Encoding.UTF8.GetBytes(str);
// 输出 byte 数组的内容
Console.WriteLine("Byte array contents:");
foreach (byte b in bytes)
{
Console.Write(b + " ");
}
}
}
str,内容为 "Hello, World!"。Encoding.UTF8.GetBytes 方法将字符串转换为字节数组。这里使用的是 UTF-8 编码方式,可以根据需要选择其他编码(如 Encoding.ASCII 或 Encoding.Unicode)。如果需要其他编码方式或进一步的处理,请根据需求调整代码。
上一篇:delegate c#
Laravel PHP 深圳智简公司。版权所有©2023-2043 LaravelPHP 粤ICP备2021048745号-3
Laravel 中文站