string strName = "aea十的个";
byte[] bytInfo = System.Text.Encoding.Default.GetBytes(strName); ushort[] Format1 = new ushort[11];//改成ushort[] Format1 = new ushort[bytInfo.Length]
for (int i = 0; i < 10; i++)//这里的"i < 10"是错的,bytInfo的长度只有9
{
Format1[i] = bytInfo[i];//下标越界
}
Format1[10] = '\0';
byte[] bytInfo = System.Text.Encoding.Default.GetBytes(strName); ushort[] Format1 = new ushort[11];//改成ushort[] Format1 = new ushort[bytInfo.Length]
for (int i = 0; i < 10; i++)//这里的"i < 10"是错的,bytInfo的长度只有9
{
Format1[i] = bytInfo[i];//下标越界
}
Format1[10] = '\0';
还是先转换成byte[] 然后把每个byte转换成ushort? string strName = "aea十的个"; ushort[] _ValueUShort = new ushort[strName.Length];
for (int i = 0; i != strName.Length; i++)
{
_ValueUShort[i] = (ushort)strName[i];
}