1.序列化 
public static byte[] SerializeObject(object obj)
        {
            if (obj == null)
                return null;
            MemoryStream ms = new MemoryStream();
            BinaryFormatter formatter = new BinaryFormatter();
            formatter.Serialize(ms, obj);
            ms.Position = 0;
            byte[] bytes = new byte[ms.Length];
            ms.Read(bytes, 0, bytes.Length);
            ms.Close();
            return bytes;
        }

string objectString=System.Convert.ToBase64String(SerializeObject(importedObj));

2.反序列化
   public static object DeserializeObject(byte[] bytes)
        {
            object obj = null;
            if (bytes == null)
                return obj;
            MemoryStream ms = new MemoryStream(bytes);
            ms.Position = 0;
            BinaryFormatter formatter = new BinaryFormatter();
            obj = formatter.Deserialize(ms);
            ms.Close();
            return obj;
        }

 

相关文章:

  • 2021-12-11
  • 2022-03-09
  • 2022-02-17
  • 2022-01-26
  • 2021-06-23
  • 2022-01-08
猜你喜欢
  • 2022-12-23
  • 2021-10-05
  • 2021-10-18
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案