• 序列化 和 反序列化 类


    public class Formater
        {
            public static byte[] Serialize(Object _object)
            {
                BinaryFormatter binaryFormatter = new BinaryFormatter();
                MemoryStream ms = new MemoryStream();
              
                binaryFormatter.Serialize(ms, _object);
              
                ms.Position = 0;
              
                byte[] b;
                b = new Byte[ms.Length];
                ms.Read(b, 0, b.Length);
                ms.Close();
                return b;
            }
            public static Object Deserialize(byte[] serializes)
            {
                Object obj = new object();
                if (serializes.Length == 0) return null;
                try
                {
                    BinaryFormatter binaryFormatter = new BinaryFormatter();
                    MemoryStream ms = new MemoryStream();
                    ms.Write(serializes, 0, serializes.Length);
                    ms.Position = 0;

                    obj = binaryFormatter.Deserialize(ms);
                    ms.Close();
                }
                catch
                {
                    obj = null;
                }
                return obj;
            }
        }

  • 相关阅读:
    方法的形式参数是类名的时候如何调用
    成员变量与局部变量的区别
    如何选择适合自己的Linux版本
    MySQL数据库的特点和优势
    面向对象学生类和手机类的使用
    面向对象基本概述
    数据库概念介绍
    二位数组的求和
    二维数组遍历
    SpringBoot与SpringMVC的区别是什么?
  • 原文地址:https://www.cnblogs.com/zlddtt/p/1544230.html
Copyright © 2020-2023  润新知