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. php中的$_GET怎样获取带有井号“#”的參数

    <?php echo $_GET['key']; ?> 当url为http://test.com/c.php?key=999时,正常输出:999 当url为http://test.com/ ...

  2. 将Model实体类对象作为WebService接口参数(转)

    转自:http://www.cnblogs.com/fengyishou/archive/2009/02/27/1399281.html 关于web服务的有关基础知识,看了基本书,但是不敢在这里乱说, ...

  3. 【转】GitHub 优秀的 Android 开源项目

    转自:http://blog.csdn.net/shulianghan/article/details/18046021 主要介绍那些不错个性化的View,包括ListView.ActionBar.M ...

  4. c#、sql、asp.net、js、ajax、jquery大学知识点笔记

    <table cellSpacing="0" cellPadding="0" width="609" height="470 ...

  5. hibernate 获取实体的表名、主键名、列名(转载+修改)

    package com.escs.utils; import java.util.Iterator; import org.hibernate.cfg.AnnotationConfiguration; ...

  6. DTD

    DTD(文档类型定义)的作用是定义 XML 文档的合法构建模块. 它使用一系列的合法元素来定义文档结构. DTD 可被成行地声明于 XML 文档中,也可作为一个外部引用. 内部的 DOCTYPE 声明 ...

  7. Binder机制,从Java到C (5. IBinder对象传递形式)

    1.IBinder的传递 Binder IPC通信中,Binder是通信的媒介,Parcel是通信的內容.远程调用过程中,其参数都被打包成Parcel的形式來传递.IBinder对象当然也不例外,在前 ...

  8. 【转】jQuery each函数中的continue及break

    continue :return true; break :return false; 也可以利用return即可跳出jQuery 来源:http://bie.xiaowangge.info/brow ...

  9. [转]iOS Anti-Debugging Protections

    source-1: http://www.coredump.gr/articles/ios-anti-debugging-protections-part-1/ source-2: http://ww ...

  10. 使用WCF扩展记录服务调用时间

    随笔- 64  文章- 0  评论- 549  真实世界:使用WCF扩展记录服务调用时间   WCF 可扩展性 WCF 提供了许多扩展点供开发人员自定义运行时行为. WCF 在 Channel Lay ...