// 将 byte[] 转换为 string 的示例代码
using System;
using System.Text;
class Program
{
static void Main()
{
// 定义一个字节数组
byte[] bytes = { 72, 101, 108, 108, 111 };
// 使用 UTF8 编码将字节数组转换为字符串
string result = Encoding.UTF8.GetString(bytes);
// 输出结果
Console.WriteLine(result); // 输出: Hello
}
}
bytes
,这些值对应于字符串 "Hello"。Encoding.UTF8.GetString
方法:这个方法可以将字节数组转换为字符串。这里我们使用了 UTF-8 编码,这是一种常见的字符编码方式。如果你需要将其他编码格式的字节数组转换为字符串,可以根据需要选择不同的编码方式,例如 Encoding.ASCII
或 Encoding.Unicode
。
上一篇:c# byte转int
下一篇:c# maui
Laravel PHP 深圳智简公司。版权所有©2023-2043 LaravelPHP 粤ICP备2021048745号-3
Laravel 中文站