0
点赞
收藏
分享

微信扫一扫

C++ :模板特化

穿裙子的程序员 02-29 16:30 阅读 2
c#java前端

 /// <summary>
        /// 将对象转换成字节数组
        /// </summary>
        /// <param name="obj"></param>
        /// <returns></returns>
        private byte[] objToBytes(object obj)
        {
            MemoryStream ms = new MemoryStream();
            BinaryFormatter bf = new BinaryFormatter();
            bf.Serialize(ms, obj);
            byte[] arrBytes = ms.GetBuffer();
            ms.Close();
            return arrBytes;
        }

 /// <summary>
        /// 将字节数组转成字符
        /// </summary>
        /// <param name="bytes"></param>
        /// <returns></returns>
        private string bytesToString(byte[] bytes)
        {
            BinaryFormatter bfFormatter = new BinaryFormatter();
            string str = bfFormatter.Deserialize(new MemoryStream(bytes)) as string;
            return str;
        }

举报

相关推荐

0 条评论