Non puoi selezionare più di 25 argomenti
Gli argomenti devono iniziare con una lettera o un numero, possono includere trattini ('-') e possono essere lunghi fino a 35 caratteri.
|
- using System.IO;
- using System.Runtime.Serialization.Formatters.Binary;
- namespace StuMgmLib
- {
- class Utility
- {
- /// <summary>
- /// 序列化
- /// </summary>
- public static byte[] SerializeBin<T>(T c)
- {
- MemoryStream ms = new MemoryStream();
- BinaryFormatter iFormatter = new BinaryFormatter();
- iFormatter.Serialize(ms, c);
- byte[] buf = ms.GetBuffer();
- return buf;
- }
-
- /// <summary>
- /// 反序列化
- /// </summary>
- public static T DeserializeBin<T>(byte[] buf)
- {
- MemoryStream ms = new MemoryStream(buf);
- BinaryFormatter iFormatter = new BinaryFormatter();
- var obj = (T)iFormatter.Deserialize(ms);
- return obj;
- }
- }
-
- }
|