using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using System.Xml.Serialization;
using System.Runtime.Serialization.Formatters.Binary;
using System.Runtime.Serialization.Formatters.Soap; namespace Serialization
{
class Program
{
static void Main(string[] args)
{
Student stu = new Student("张三", , "登山"); ////二进制序列化
//BinaryFormatter bf = new BinaryFormatter();
//FileStream fs = new FileStream(@"D:\stu.ss", FileMode.Create);
//bf.Serialize(fs, stu);
//fs.Close(); ////二进制反序列化
//BinaryFormatter bf = new BinaryFormatter();
//FileStream fs = new FileStream(@"D:\stu.ss", FileMode.Open);
//Student student = (Student)bf.Deserialize(fs);
//student.method(); ////xml序列化
//XmlSerializer xml = new XmlSerializer(typeof(Student));
//FileStream fs = new FileStream(@"D:\stu.xml",FileMode.Create);
//xml.Serialize(fs, stu);
//fs.Close(); ////xml反序列化
//XmlSerializer xml = new XmlSerializer(typeof(Student));
//FileStream fs = new FileStream(@"D:\stu.xml", FileMode.Open);
//Student student = (Student)xml.Deserialize(fs);
//student.method(); ////soap序列化
//SoapFormatter soap = new SoapFormatter();
//FileStream fs = new FileStream(@"D:\stu.soap", FileMode.Create);
//soap.Serialize(fs, stu);
//fs.Close(); //soap反序列化
SoapFormatter soap = new SoapFormatter();
FileStream fs = new FileStream(@"D:\stu.soap", FileMode.Open);
Student student = (Student)soap.Deserialize(fs);
student.method(); }
} [Serializable]
public class Person
{
public Person()
{ } public Person(string name, int age)
{
this.Name = name;
this.Age = age;
} public string Name
{
get;
set;
}
public int Age
{
get;
set;
}
} [Serializable]
public class Student : Person
{
public Student()
{ } public Student(string name, int age, string hobby)
: base(name, age)
{
this.Hobby = hobby;
} public string Hobby
{
get;
set;
} public void method()
{
Console.WriteLine("大家好,我叫{0},今年{1}岁,我喜欢{2}", this.Name, this.Age, this.Hobby);
//Console.ReadLine();
}
}
}

C# 序列化(Binary、Xml、Soap)的更多相关文章

  1. C# 序列化与反序列化之Binary与Soap无法对泛型List<T>进行序列化的解决方案

    C# 序列化与反序列化之Binary与Soap无法对泛型List<T>进行序列化的解决方案 新建Console控制台项目项目,然后添加Team和Person 这2个类,如下: Team和P ...

  2. .NET 二进制序列化器,SOAP序列化器,XML序列化器

    这里就不说JSON序列化了,只介绍三种:二进制序列化器,SOAP序列化器,XML序列化器 直接上代码: /// <summary> /// 二进制序列化器. /// 最节省流量,压缩程度最 ...

  3. ILJMALL project过程中遇到Fragment嵌套问题:IllegalArgumentException: Binary XML file line #23: Duplicate id

    出现场景:当点击"分类"再返回"首页"时,发生error退出   BUG描述:Caused by: java.lang.IllegalArgumentExcep ...

  4. Binary XML file line #2: Error inflating

    06-27 14:29:27.600: E/AndroidRuntime(6936): FATAL EXCEPTION: main 06-27 14:29:27.600: E/AndroidRunti ...

  5. Android项目部署时,发生AndroidRuntime:android.view.InflateException: Binary XML file line #168: Error inflating class错误

    这个错误也是让我纠结了一天,当时写的项目在安卓虚拟机上运行都很正常,于是当我部署到安卓手机上时,点击登陆按钮跳转到用户主界面的时候直接结束运行返回登陆界面.    当时,我仔细检查了一下自己的代码,并 ...

  6. net中序列化读写xml

    参考http://www.cnblogs.com/fish-li/archive/2013/05/05/3061816.html 我们可以直接使用XmlTextReader.XmlDocument.X ...

  7. 在.net中序列化读写xml方法的总结

    在.net中序列化读写xml方法的总结 阅读目录 开始 最简单的使用XML的方法 类型定义与XML结构的映射 使用 XmlElement 使用 XmlAttribute 使用 InnerText 重命 ...

  8. bug_ _图片_android.view.InflateException: Binary XML file line #1: Error inflating class <unknown>

    =========== 1   java.lang.RuntimeException: Unable to start activity ComponentInfo{com.zgan.communit ...

  9. bug_ _ android.view.InflateException: Binary XML file line #2: Error inflating class <unknown

    ========= 5.0     android异常“android.view.InflateException: Binary XML file line # : Error inflating ...

  10. C#_在.net中序列化读写xml方法的总结

    阅读目录 开始 最简单的使用XML的方法 类型定义与XML结构的映射 使用 XmlElement 使用 XmlAttribute 使用 InnerText 重命名节点名称 列表和数组的序列化 列表和数 ...

随机推荐

  1. Luogu 2312 [NOIP2014] 解方程

    感觉好无聊. 秦九昭算法:一般地,一元n次多项式的求值需要经过(n+1)*n/2次乘法和n次加法,而秦九韶算法只需要n次乘法和n次加法.在人工计算时,一次大大简化了运算过程.(百度百科) 具体来说怎么 ...

  2. java 中一个char包含几个字节

    背景   char包含几个字节可能记得在上学的时候书上写的是2个字节,一直没有深究,今天我们来探究一下到底一个char多少个字节? Char   char在设计之初的时候被用来存储字符,可是世界上有那 ...

  3. 后台传Map到ftl

    userInfo是后台传过来的Map <#list userInfo?keys as key> <tr > <td class="case_id" d ...

  4. easyUI datagrid 分页参数page和rows

    Struts2获取easyUI datagrid 分页参数page和rows 用pageHelper分页时,只要是能够获取前台传来的两个参数page和rows基本就完成了很大一部分. 获取方法:定义两 ...

  5. Notepad++一键编译运行(Python、Java、C++)

    Python 需要事先安装Python配置好环境变量.建议使用Anaconda,方便. 在Notepad按F5,输入如下 cmd /k chdir /d $(CURRENT_DIRECTORY) &a ...

  6. AU3获取系统激活信息

    If IsActivated() = False Then ;InstallProductKey($OSkey) ; installs a product key and also activates ...

  7. Zoey.Dapper--Dapper扩展之把SQL语句放到文件中

    介绍 不知道大家在用Dapper的时候SQL语句是写到哪的,目前看网上的例子都是写到类里面的. 此项目的目的是把SQL语句放到文件(xml)中 目前只是初步版本,只是说明了意图,后面会持续完善和优化 ...

  8. c#线程-线程同步

    线程同步 上一篇介绍了如何开启线程,线程间相互传递参数,及线程中本地变量和全局共享变量区别. 本篇主要说明线程同步. 如果有多个线程同时访问共享数据的时候,就必须要用线程同步,防止共享数据被破坏.如果 ...

  9. linux影响上传文件大小的因素

    主要是从三个方面 ①.php代码方面(这个无需说明) ②.php.ini配置 max_execution_time = 600 ;每个PHP页面运行的最大时间值(秒),默认30秒max_input_t ...

  10. (原创)D-query SPOJ - DQUERY(莫队)统计不同数的数量

    A - D-query Given a sequence of n numbers a1, a2, ..., an and a number of d-queries. A d-query is a ...