写一个c#Byte 转string的代码
以下是将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/ePZL 著作权归作者所有。请勿转载和采集!