原文:http://stackoverflow.com/questions/302821/serialization-in-c-without-using-file-system

public static byte[] Serialize<T>(T t) {
            IFormatter formatter = new BinaryFormatter();
            using (MemoryStream stream = new MemoryStream()) {
                formatter.Serialize(stream, t);
                return stream.ToArray();
            }
        }

        public static T Deserialize<T>(byte[] b) {
            IFormatter formatter = new BinaryFormatter();
            using (MemoryStream stream = new MemoryStream(b)) {
                return (T)formatter.Deserialize(stream);
            }
        }

相关文章:

  • 2022-02-20
  • 2022-12-23
  • 2022-12-23
  • 2021-06-29
  • 2022-12-23
  • 2021-10-12
  • 2021-10-10
  • 2021-09-10
猜你喜欢
  • 2022-12-23
  • 2021-10-05
  • 2022-12-23
  • 2021-06-25
  • 2022-12-23
  • 2022-12-23
  • 2021-06-03
相关资源
相似解决方案