C# Byte[] 数组转换为字符串的代码示例
以下是将 byte[] 转换为 string 的示例代码:
byte[] byteArray = { 72, 101, 108, 108, 111, 32, 87, 111, 114, 108, 100 }; // 'Hello World' 的 ASCII 码
string result = System.Text.Encoding.ASCII.GetString(byteArray);
Console.WriteLine(result); // 输出:Hello World
此代码使用 System.Text.Encoding.ASCII 类中的 GetString 方法将 byteArray 转换为字符串。此方法将字节数组解码为 ASCII 字符序列。如果需要使用其他编码,请使用相应的 Encoding 类替换 ASCII。
原文地址: https://www.cveoy.top/t/topic/nZkk 著作权归作者所有。请勿转载和采集!