C#中byte数组与string类型之间的转换

时间:2025-03-16 07:46:42

string类型转换为byte[]:

string str = "Test";
byte[] bytTemp = (str);

byte[]转换为string

string strTemp = (bytTemp);

但是得到的结果为54-65-73-74,这里需要进行转换
转换代码:

string[] strSplit = ('-');   
byte[] bytTemp2 = new byte[];
for(int i = 0; i < ; i++)
{
	bytTemp2[i] = (strSplit[i],);
}
string strResult = (bytTemp2);

可以看到strResult = “Test”

相关文章