您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

40 行
959 B

  1. using System;
  2. using System.Collections.Generic;
  3. using System.IO;
  4. using System.Runtime.Serialization.Formatters.Binary;
  5. using System.Text;
  6. using System.Data;
  7. namespace StuMgmLib.MyNameSpace
  8. {
  9. public class BinaryED // 序列化与反序列化
  10. {
  11. /// <summary>
  12. /// 序列化
  13. /// </summary>
  14. public static byte[] Serialize<T>(T c)
  15. {
  16. MemoryStream ms = new MemoryStream();
  17. BinaryFormatter iFormatter = new BinaryFormatter();
  18. iFormatter.Serialize(ms, c);
  19. byte[] buf = ms.GetBuffer();
  20. return buf;
  21. }
  22. /// <summary>
  23. /// 反序列化
  24. /// </summary>
  25. public static T Deserialize<T>(byte[] buf)
  26. {
  27. MemoryStream ms = new MemoryStream(buf);
  28. BinaryFormatter iFormatter = new BinaryFormatter();
  29. var obj = (T)iFormatter.Deserialize(ms);
  30. return obj;
  31. }
  32. }
  33. }