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. 触摸屏、X11去掉鼠标

    cursor disable in X11 Last updated 8 years ago 摘自:http://www.noah.org/wiki/cursor_disable_in_X11 Whe ...

  2. 在windows中安装OpenSSH,无密码登录,永远不断线

    到这里下载最新安装包:https://github.com/PowerShell/Win32-OpenSSH/releases下载下来解压,然后用管理员打开服务器自带的PowerShell,运行下列命 ...

  3. IntelliJ Idea 免费激活方法

    文章介绍 文章不错,指的研究一下,idea的联网激活确实有可行性,但是上有政策,下有对策,如何才能保护版权,是一个值得深思的问题. 文章属于转载,文末有文章来源,转载注明出处. 1 激活码激活 到网站 ...

  4. TestNG入门

    在Eclipse中安装TestNG 打开Eclipse   Help ->Install New Software ,   然后Add   "http://beust.com/ecli ...

  5. ASP.NET MVC 视图层-生成链接相关(Html.ActionLink,Url.Action)

    1. @Html.ActionLink()  参考 也是使用在chtml模板中,返回参数中指定controller.指定action的所生成的超链接标签<a>标签html文本.如果没有指定 ...

  6. linux内核中的##__VA_ARGS__有什么作用?

    答:   1.__VA_ARGS__是一个可变参数宏: 2. 当可变参数的个数为0时,这里的##起到把前面多余的","去掉的作用,否则会编译出错: 3. 示例 3.1 #defin ...

  7. 【转】oracle远程导入数据库

    源地址:http://blog.chinaunix.net/uid-20980141-id-447996.html

  8. Ready api groovy script 参数化

    def token_type =context.expand ('${#Project#token_type}') def access_token = context.expand('${#Proj ...

  9. 微信网页授权操作逻辑封装-C#实例

    http://blog.csdn.net/u011127019/article/details/52650619

  10. 黑马集合学习 自定义ArrayList01

    package demo; import java.util.Arrays; public class MyArrayList<T> { Object[] t; int size; pri ...