- 浏览: 142286 次
- 性别:
- 来自: 火星
文章分类
最新评论
-
hxl860217:
...
为什么要使用代理类(代理模式) -
showzh:
myeclipse没有这个菜单
如何卸载Eclipse插件 -
xiefei3k:
不给力啊 从数据里查出用户名的结果里面进行判断的代码呢。
...
jquery servlet jsp完成用户名存在验证 $.ajax() -
songfantasy:
不错。挺好的。
如何卸载Eclipse插件 -
tongliaozhang:
只适合数字吧 如果有汉字怎么办呢我的第一列中有A01 这样的记 ...
利用PL/SQL Developer工具导入excel数据
1序列化:是将对象的状态存储到特定的存储介质中的过程,在序列化的过程 中,会将对象的公有成员,私有成员包括类名,都转换成数据流的形式,存储到存储介质中, 2 3反序列化: 是从将特定存储介质中闺怨数据重新构建对象的过程.通过反序列化,可以将庆文件上的对象信息读取,然后重新构建为对象. 4 5一个类要实现序列化,这个类的特性必须被标识为[Serializable] 6 7序列化保存到存储介质上的文件为二进制文件,因此要对二进制进行操作,要引入命名空间: 8 9using System.Runtime.Seriialization.Formatters.Binary; 10 11对二进制操作,就要用到流,要引入命名空间 12 13using System.IO; 14 15下面是实例 16 17using System; 18using System.Collections.Generic; 19using System.Text; 20 21namespace SerializableTest 22{ 23 24 [Serializable] //特性,表明此类可以被序列化 25 public class Students 26 { 27 private string name; 28 29 public string Name 30 { 31 get { return name; } 32 set { name = value; } 33 } 34 private int age; 35 36 public int Age 37 { 38 get { return age; } 39 set { age = value; } 40 } 41 42 } 43} 44 45 46 47using System; 48using System.Collections.Generic; 49using System.Text; 50using System.IO; 51using System.Runtime.Serialization.Formatters.Binary; 52 53namespace SerializableTest 54{ 55 /**//// <summary> 56 /// 序列化的类 57 /// </summary> 58 public class SerializableClass 59 { 60 /**//// <summary> 61 /// 序列化学生类的信息 62 /// </summary> 63 /// <param name="student"></param> 64 public void Serial(Students student) 65 { 66 FileStream fs = new FileStream(@"c:\test.bin", FileMode.OpenOrCreate); 67 BinaryFormatter bf = new BinaryFormatter(); 68 bf.Serialize(fs, student); 69 fs.Close(); 70 } 71 72 /**//// <summary> 73 /// 反序列化学生类的信息 74 /// </summary> 75 /// <returns></returns> 76 77 public Students DeSerial() 78 { 79 FileStream fs = new FileStream(@"c:\test.bin", FileMode.OpenOrCreate); 80 BinaryFormatter bf = new BinaryFormatter(); 81 Students stu = bf.Deserialize(fs) as Students; 82 fs.Close(); 83 return stu; 84 85 } 86 87 /**//// <summary> 88 /// 序列化泛型集合 89 /// </summary> 90 /// <param name="stuList"></param> 91 public void SerialList(List<Students> stuList) 92 { 93 94 FileStream fs = new FileStream(@"c:\test.txt", FileMode.OpenOrCreate); 95 BinaryFormatter bf = new BinaryFormatter(); 96 97 bf.Serialize(fs, stuList); 98 99 fs.Close(); 100 101 } 102 103 /**//// <summary> 104 /// 反序列化泛型集合 105 /// </summary> 106 /// <returns></returns> 107 public List<Students> DeSerialList() 108 { 109 FileStream fs = new FileStream(@"c:\test.txt", FileMode.OpenOrCreate); 110 BinaryFormatter bf = new BinaryFormatter(); 111 List<Students> stuList = bf.Deserialize(fs) as List<Students>; 112 fs.Close(); 113 return stuList; 114 } 115 116 117 } 118} 119 120 121using System; 122using System.Collections.Generic; 123using System.Text; 124 125 126namespace SerializableTest 127{ 128 class Program 129 { 130 static void Main(string[] args) 131 { 132 133 SerializableClass sc = new SerializableClass(); 134 Students student = new Students(); 135 student.Name = "miaoqing"; 136 student.Age = 24; 137 138 //调用对类序列化的方法 139 sc.Serial(student); 140 //调用对类反序列化的方法 141 Students stuDe = sc.DeSerial() as Students; 142 Console.WriteLine("对Student类的序列化的输出"); 143 Console.WriteLine(stuDe.Name + stuDe.Age); 144 145 //Student 类 泛型集合 146 List<Students> stuList = new List<Students>(); 147 148 Students stu = new Students(); 149 stu.Name = "sofie"; 150 stu.Age = 21; 151 stuList.Add(stu); 152 153 Students stu1 = new Students(); 154 stu1.Name = "jrian"; 155 stu1.Age = 26; 156 stuList.Add(stu1); 157 158 //调用对泛型序列化的方法 159 sc.SerialList(stuList); 160 161 //调用对泛型反序列化的方法 162 List<Students> stuList1 = sc.DeSerialList(); 163 foreach (object obj in stuList1) 164 { 165 Students stuObj = obj as Students; 166 Console.WriteLine(stuObj.Name + stuObj.Age); 167 } 168 } 169 } 170 171}
http://www.cnblogs.com/pengpeng614/archive/2008/08/29/1279719.html
发表评论
-
c#中 父类调用子类的属性、方法
2016-08-17 17:50 4372我们习惯认为,子类对父类是不可见的,或者说父类不知道 ... -
在IIS 7.5中部署Web项目
2013-08-16 15:49 705http://www.soaspx.com/dotnet/se ... -
c# 拖动控件闪烁
2012-11-06 14:41 1317最近几天在做画线框的工作,类似于截屏之后修改截屏大小的那种, ... -
UDP用同一端口收发数据 c#
2012-10-17 13:02 4684之前用UdpClient,发现当开了一个端口用于监听接收 ... -
Windows 7下VS2008升级补丁
2012-06-04 11:29 5在Windows 7下,VS2008试用版无法正常升级到正式版 ... -
C#读取exe版本号
2012-04-20 10:44 1184//通常我们做软件自动更新,需要比较新文件与旧文件的版本 ... -
c#读取php序列化字符串
2011-06-04 16:25 1135详见附件 -
c#获取网页代码
2011-03-22 16:58 1071using System; using System. ... -
.NET连接mysql数据库 MySQLDriverCS.dll
2011-03-22 16:30 1647string mysqlConn = new MySQ ... -
c#委托相当于c++的回调函数(函数指针)
2010-05-12 17:08 3485回调函数,就是由你自己写的。你需要调用另外一个函 ... -
一些容易出错的地方(持续更新)
2010-04-16 12:39 7321.在html 或者aspx文件里去掉这段代码<!DOC ... -
泛型类(普通类)中的普通方法和泛型方法
2009-10-31 16:48 915在普通类中用泛型方法 public class A { ... -
c#泛型(包括泛型抽象类的继承)
2009-10-17 19:26 35471.泛型和泛型强制转换 using System; ... -
.net提供的5种request-response方法一
2009-09-06 17:16 1735.net提供了三种基本方法和两种底层方法来发送ht ... -
C#三种模拟自动登录和提交POST信息的实现方法
2009-06-09 10:57 3190C#三种模拟自动登录和提交POST信息的实现方法 ... -
.Net下WinForm换肤控件整理
2009-06-08 09:13 22551. 东日IrisSkin IrisSkin 共有两个版本,一 ... -
论反射
2009-05-27 10:20 8081 反射 反射是很多类库在实现一些很炫的功能的时候会常用 ... -
C#装箱与拆箱
2009-04-30 14:54 970要掌握装箱与拆箱,就必须了解CTS及它的特点。 NET重要技 ... -
遍历页面上的下拉框元素,设置初始值的4种写法
2009-04-30 14:51 1202foreach (Control co ... -
c# 特性/属性(Attribute) 以及使用反射查看自定义特性
2009-04-20 16:10 4708可能很多人还不了解特性,所以我们先了解一下 ...
相关推荐
什么叫反序列化? 就是再把介质中的东西还原成对象,把石子还原成人的过程。 在进行这些操作的时候都需要这个可以被序列化,要能被序列化,就得给类头加[Serializable]特性。 通常网络程序为了传输安全才这么做。不...
C# xml序列化及反序列化(解析xml为对象及对象转xml保存),方法一反序列化取节点KV值,方法二反序列化取节点标签值,方法三取节点KV值,并增加节点对象数组及节点标签组合反序列化
C#序列化与反序列化,C#序列化与反序列化,很清晰的一个示例
二进制序列化:对象序列化之后是二进制形式的,通过BinaryFormatter类来实现的,这个类位于System.Runtime.Serialization.Formatters.Binary命名空间下。 SOAP序列化:对象序列化之后的结果符合SOAP协议,也就是可以...
c#对象序列化与反序列化实例c#对象序列化与反序列化实例c#对象序列化与反序列化实例c#对象序列化与反序列化实例c#对象序列化与反序列化实例c#对象序列化与反序列化实例
C#高级序列化与反序列化_C#高级序列化与反序列化_C#高级序列化与反序列化_C#高级序列化与反序列化
序列化和反序列化的封装类,只要调用就行 序列化和反序列化的封装类 序列化和反序列化的封装类 序列化和反序列化的封装类 序列化和反序列化的封装类
C#序列化和反序列化,概念,要素,作用,例子等
自己写的C#序列化和反序列化案例,打开软件添加信息序列化到文本,打开软件将文本信息显示到软件Dategridview控件
C#序列化,反序列化对象完整代码
C# 序列化 xml soap json binary
C# 序列化-反序列化.cs
C# 数组与序列化C# 数组与序列化C# 数组与序列化C# 数组与序列化C# 数组与序列化C# 数组与序列化C# 数组与序列化
.net c# 序列化和反序列.net c# 序列化和反序列.net c# 序列化和反序列.net c# 序列化和反序列.net c# 序列化和反序列.net c# 序列化和反序列
此资源是《C#序列化和反序列化之一-二进制序列化》的源代码,博文地址是:http://blog.csdn.net/jiangzhanchang/article/details/6892262
实现C#序列化和反序列化XML-读取wordXML内容
基于WindowForm应用程序C#语言通过实际案例实现将对象保存到文件及从已保存的文件中读取对象(直接保存与读取、通过序列化与反序列化方式进行对象保存与读取)