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 类的对象 −
Employee emp = new Employee(001, "Jim", 30000); bFormat.Serialize(fStream, emp);
广告
数据结构
网络
RDBMS
操作系统
Java
iOS
HTML
CSS
Android
Python
C 编程
C++
C#
MongoDB
MySQL
Javascript
PHP