C# 对象序列化
要进行对象序列化,你需要参考以下代码。在此,我们使用了 BinaryFormatter.Serialize (stream, reference) 方法来序列化我们的示例对象。
我们此处设置了一个构造函数 −
public Employee(int id, string name, int salary) {
this.id = id;
this.name = name;
this.salary = salary;
}现在设置文件流 −
FileStream fStream = new FileStream("d:\
ew.txt", FileMode.OpenOrCreate);
BinaryFormatter bFormat = new BinaryFormatter();员工类的对象 −
Employee emp = new Employee(001, "Jim", 30000); bFormat.Serialize(fStream, emp);
广告
数据结构
网络
关系型数据库管理系统
操作系统
Java
iOS
HTML
CSS
安卓
Python
C 编程
C++
C#
MongoDB
MySQL
Javascript
PHP