/// <summary> /// 将byte数组反序列化为稀疏矩阵(按C#自带的反序列化) /// </summary> /// <param name="T">泛型</param> /// <param name="bytes">序列化处理后的字节数组</param> public static byte[,] Desrialize(byte[,] mat, byte[] bytes, int startoffset, int PointLength) { try { tupletype tu = new tupletype(); byte[] td_byte = new byte[startoffset]; for (byte i = 0; i < startoffset; i++) { td_byte[i] = bytes[i]; } // If the system architecture is little-endian (that is, little end first), // reverse the byte array. //if (BitConverter.IsLittleEndian) // Array.Reverse(td_byte); int td = BitConverter.ToInt32(td_byte, 0); for (int i = 0; i < td; i++) { byte[] tu_byte = new byte[PointLength]; for (byte j = 0; j < PointLength; j++) { tu_byte[j] = bytes[startoffset + PointLength * i + j]; } object tu_obj = tu; ByteAndStruct.ByteArrayToStructure(tu_byte, ref tu_obj, 0); tu = (tupletype)tu_obj; mat[tu.x, tu.y] = tu.value; } } catch (Exception ex) { throw new Exception("反序列化失败,原因:" + ex.Message); } return(mat); }