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 重命名节点名称 列表和数组的序列化 列表和数 ...
随机推荐
- 红帽企业版RHEL7.1在研域工控板上,开机没有登陆窗口 -- 编写xorg.conf 简单三行解决Ubuntu分辩率不可调的问题
红帽企业版RHEL7.1在研域工控板上,开机没有登陆窗口 没有登陆窗口 的原因分析: 没有登陆窗口的原因是因为有多个屏幕在工作,其中一个就是build-in 屏幕(内置的虚拟屏幕)和外接的显示器,并且 ...
- 查看Linux各发行版本方法
SUSE: cat /etc/SuSE-release Slackware: cat /etc/slackware-version Redhat: cat /etc/redhat-releas ...
- [学习笔记]fork写实复制
#include<stdio.h> #include<stdlib.h> #include<string.h> #include <unistd.h> ...
- CIFAR-10 模型
Code: https://github.com/tensorflow/models/tree/master/official/resnet Data: http://www.cs.toronto.e ...
- python常见的加密解密
#!/usr/bin/env python ''' Python Crypto Wrapper - By Chase Schultz Currently Supports: AES-256, RSA ...
- python连接数据库--查询数据
#!/usr/bin/python # -*- coding: utf-8 -*- import pymysql def fileDB(): # 打开数据库连接(ip/数据库用户名/登录密码/数据库名 ...
- maredit测试
int main() { } void addTotail(ListNode *& pHead, int value) { ListNode *node = new ListNode(); n ...
- oracle 逻辑体系结构详解
以前对数据库的了解大多数是集中在mysql,最近工作里面一直使用的是oracle,虽然说在互联网行业mysql大行其道,但是一些传统行业或者是金融领域还是更加倾向于使用oracle,sqlserver ...
- CHNS类
NS类集合介绍 1.常用部分 NSDictionary NSString NSArray 数组 NSTimer 定时器 NSRange 范围 NSNotification 2.网络相关 NSURLCo ...
- 787. Cheapest Flights Within K Stops
There are n cities connected by m flights. Each fight starts from city u and arrives at v with a pri ...