c# 二进制序列化

    public static T Deserialize<T, S>(S stream) where S : Stream where T : class, new()
        {
            using (stream)
            {
                BinaryFormatter formatter = new BinaryFormatter();
                return (T)formatter.Deserialize(stream);
            }
        }

        public static void Serialize<T, S>(T obj, S stream) where S : Stream where T : class, new()
        {
            using (stream)
            {
                BinaryFormatter formatter = new BinaryFormatter();
                formatter.Serialize(stream, obj);
            }
        }
原文地址:https://www.cnblogs.com/feizianquan/p/9720890.html