C# 序列化(Binary、Xml、Soap)
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)的更多相关文章
- C# 序列化与反序列化之Binary与Soap无法对泛型List<T>进行序列化的解决方案
C# 序列化与反序列化之Binary与Soap无法对泛型List<T>进行序列化的解决方案 新建Console控制台项目项目,然后添加Team和Person 这2个类,如下: Team和P ...
- .NET 二进制序列化器,SOAP序列化器,XML序列化器
这里就不说JSON序列化了,只介绍三种:二进制序列化器,SOAP序列化器,XML序列化器 直接上代码: /// <summary> /// 二进制序列化器. /// 最节省流量,压缩程度最 ...
- ILJMALL project过程中遇到Fragment嵌套问题:IllegalArgumentException: Binary XML file line #23: Duplicate id
出现场景:当点击"分类"再返回"首页"时,发生error退出 BUG描述:Caused by: java.lang.IllegalArgumentExcep ...
- 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 ...
- Android项目部署时,发生AndroidRuntime:android.view.InflateException: Binary XML file line #168: Error inflating class错误
这个错误也是让我纠结了一天,当时写的项目在安卓虚拟机上运行都很正常,于是当我部署到安卓手机上时,点击登陆按钮跳转到用户主界面的时候直接结束运行返回登陆界面. 当时,我仔细检查了一下自己的代码,并 ...
- net中序列化读写xml
参考http://www.cnblogs.com/fish-li/archive/2013/05/05/3061816.html 我们可以直接使用XmlTextReader.XmlDocument.X ...
- 在.net中序列化读写xml方法的总结
在.net中序列化读写xml方法的总结 阅读目录 开始 最简单的使用XML的方法 类型定义与XML结构的映射 使用 XmlElement 使用 XmlAttribute 使用 InnerText 重命 ...
- 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 ...
- 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 ...
- C#_在.net中序列化读写xml方法的总结
阅读目录 开始 最简单的使用XML的方法 类型定义与XML结构的映射 使用 XmlElement 使用 XmlAttribute 使用 InnerText 重命名节点名称 列表和数组的序列化 列表和数 ...
随机推荐
- noi.ac day1t1 candy
传送门 分析 我们知道如果设A,B分别为将两家店从大到小排序之后各自的前缀和,则 Ans=Max{Min{A[i],B[j]}-W*(i+j)}. 为了得到这个Ans我们可以枚举两个数的Min,然后剩 ...
- java反射中,Class.forName和classloader的区别
http://blog.csdn.net/qq_27093465/article/details/52262340
- javascript使用ajax方式
ajax请回和回应实例: function showContent(type) { //create obj var xmlhttp; if (window.XMLHttpRequest) { //c ...
- C# 顺序表---增删改查--逆至--删除最小值
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.T ...
- DB2安装步骤
##################################DB2的安装########################### ## 安装前准备 ## 关闭内存地址随机化机制 vi /etc/ ...
- Django / Python 链接MySQL数据库
https://www.cnblogs.com/wupeiqi/articles/5237704.html python (Django)中使用MySQL 首先python3中没有 MySQLdb 需 ...
- C语言之基本编程思想与基本概念扫盲
前言:C语言是包含了很多编程的基本思想,理解C能够有助于理解其他高级语言,深刻理解编程很多基本思想:这对新手入门是有很多好处的,正所谓磨刀不误砍柴工,内功与基础修炼扎实了,才能开始盖高楼大厦. 这篇文 ...
- Kibana6.x.x——启动后警告信息:Session cookies will be transmitted over insecure connections. This is not recommended.
启动Kibana后,如果你看到如下警告信息: server log [08:03:18.001] [warning][security] Session cookies will be transmi ...
- Codeforces-D-Diverse Garland(思维)
You have a garland consisting of nn lamps. Each lamp is colored red, green or blue. The color of the ...
- Java使用Array类创建多维数组
1.创建一维数组 import java.lang.reflect.Array; public class ArrayTest { public static void main(String[] a ...