在 C# 中序列化一个对象后,我将它上传到我的数据库,每个十六进制字符串如下所示:
0x0001000000FFFFFFFF01000000000000000C0200000046496E76656E746F72794F626A6563742C2056657273696F6E3D312E302E302E302C2043756C747572653D6E65757472616C2C205075626C69634B6579546F6B656E3D6E756C6C050100000019496E76656E746F72792E496E76656E746F72794F626A65637404000000
当我反序列化时,我期望每个对象都是相同的(这意味着我的代码中有错误)。但它们不是,而是它们代表正确的唯一对象。
sql server中是否发生了某种指针关联?
序列化方法:
public byte[] serialize()
{
BinaryFormatter bf = new BinaryFormatter();
MemoryStream ms = new MemoryStream();
bf.Serialize(ms, this); //NOTE: this refers to a InventoryObject
byte[] returnVal = ms.ToArray();
ms.Close();
return returnVal;
}
反序列化方法:
public static InventoryObject deserialize(byte[] arrBytes)
{
MemoryStream memStream = new MemoryStream();
BinaryFormatter binForm = new BinaryFormatter();
memStream.Write(arrBytes, 0, arrBytes.Length);
memStream.Seek(0, SeekOrigin.Begin);
InventoryObject obj = (Object)binForm.Deserialize(memStream) as InventoryObject;
return obj ;
}