This sample shows how to turn object to byte[], as well as turn byte[] to object.

So,I can turn any types of object into byte[],which can be saved and transported properly.

Attention!Attention!Attention!(Important things should be repeated three times:))

1.Don't forget to using <System.IO; System.Runtime.Serialization.Formatters.Binary; System.Runtime.Serialization;> at the beginning of your program.

2.When you need to transport an class/struct that defined by yourself, you'd better put the definition into a DLL file and using it in your program.

3.Also,put a [Serializable] before the definition(if it is defined on your own).

 public static byte[] Object2Bytes(object obj)
{
IFormatter fmt = new BinaryFormatter();
MemoryStream ms = new MemoryStream();
fmt.Serialize(ms,obj);
return ms.GetBuffer();
} public static object Bytes2Object(byte[] bt)
{
IFormatter fmt = new BinaryFormatter();
MemoryStream ms = new MemoryStream(bt);
return (object)fmt.Deserialize(ms);
}

【C#】Switch datatype between object and byte[]的更多相关文章

  1. 论文阅读(Chenyi Chen——【ACCV2016】R-CNN for Small Object Detection)

    Chenyi Chen--[ACCV2016]R-CNN for Small Object Detection 目录 作者和相关链接 方法概括 创新点和贡献 方法细节 实验结果 总结与收获点 参考文献 ...

  2. 【WIP】客户端JavaScript Web Object

    创建: 2017/10/11   更新: 2017/10/14 标题加上[WIP],增加[TODO] 更新: 2018/01/22 更改标题 [客户端JavaScript Web Object, UR ...

  3. 【计算机视觉】Selective Search for Object Recognition论文阅读3

    Selective Search for Object Recoginition surgewong@gmail.com http://blog.csdn.net/surgewong       在前 ...

  4. 【TensorFlow】Win7下使用Object Detection API 训练自己的数据集,并视频实时检测

    说明: 图片:自己开的摄像头,截取的图片.选择了200张图片.下面会有截取的脚本. 使用labelImg工具进行图片进行标注.产生PascalVOC格式的XML文件.[labelImg工具的安装和使用 ...

  5. 【转】HTML - embed 与 object 之争

    在 HTML 里嵌入文本和图片之外的事物,就会用到嵌入标签,而嵌入标签在各浏览器之间的不统一,一直是让开发人员很头痛的问题.一切都要从嵌入 SUN 公司的 Applet Java 小程序开始. 当时, ...

  6. 【2017-02-23】switch...case...和for循环

    1.代码简化折叠: #region 标题 ... ... #endregion 一.switch...case... 1.格式 switch(变量){ case 值:代码段;break; case 值 ...

  7. 【java】对象克隆protected Object clone() throws CloneNotSupportedException

    package 对象克隆; class A implements Cloneable{//要具备clone()功能必须要实现Cloneable接口,此接口里无方法,只起标识作用. private St ...

  8. 【java】switch case支持的6种数据类型

    switch表达式后面的数据类型只能是byte,short,char,int四种整形类型,枚举类型和java.lang.String类型(从java 7才允许),不能是boolean类型. 在网上看到 ...

  9. 【转】js判断一个object对象是否为空

    判断一个对象是否为空对象,本文给出三种判断方法: 1.最常见的思路,for...in... 遍历属性,为真则为“非空数组”:否则为“空数组” for (var i in obj) { // 如果不为空 ...

随机推荐

  1. 开辟html5和css3学习随笔(2015-3-2)

    1.移动端超出指定行数隐藏并显示省略号 <!DOCTYPE html> <html> <head> <meta http-equiv="Conten ...

  2. 启用密码管理之前创建的用户连接Oracle报ORA-28002处理一则

    处理方法其实很简单.只要:     alter user <username> identified by <same password>;  这个操作后,恢复正常了 下面作个 ...

  3. Smarty属性

    Attributes [属性] 大多数函数都带有自己的属性以便于明确说明或者修改他们的行为.  smarty函数的属性很像HTML中的属性.  静态数值不需要加引号,但是字符串建议使用引号.  如果用 ...

  4. 笔试总结篇(一) : 广州X公司笔试

    一.单选题: Ps : 当时由于去广州路上颠簸很困,导致刚做几分钟题目就睡了一觉.起来发现20分钟过去了.擦擦! 1. 假设磁盘文件foobar.txt 由 6个ASCII 码字符“foobar” 组 ...

  5. 一个HttpWebRequest工具类

      using System; using System.Collections.Generic; using System.IO; using System.Linq; using System.N ...

  6. MongoDB学习3

    MongoDB学习(翻译3)   支持的where字句(比较多,今天先写一部分) 本节介绍支持的where字句 正如前面提到的,不是所有的C#表达式都支持where子句.您可以以此文为指导,或者你可以 ...

  7. 项目结构的设计(iOS篇)

    项目结构的设计(iOS篇) 本文附带源码:YoungHeart-Chapter-02.zip 在设计任何一个框架之前,都应规划好项目结构. 假定Git作为我们的项目管理工具.我们要建立两个仓库,一个用 ...

  8. SoapUI调用Web服务

    msg = string.Empty; //string sendAddr, string destAddr, string smContent, int IsNeedreport, DateTime ...

  9. urllib2 源码小剖

    urllib2 源码小剖 2013-08-25 23:38 by 捣乱小子, 272 阅读, 0 评论, 收藏, 编辑 两篇小剖已经完成: urllib 源码小剖 urllib2 源码小剖 urlli ...

  10. 一键保存网页为PDF

    一键保存网页为PDF_V1.2   福利来了,“一键保存网页为PDF”发布以来最给力的功能来了: 1.支持大部分浏览器了(添加书签方式),测试IE8\IE9.谷歌.火狐可用: 2.转换组件“ephtm ...