// ProtoBuf序列化
using(var file = System.IO.File.Create("Person.bin"))
{
ProtoBuf.Serializer.Serialize(file, person);
}
// ProtoBuf反序列化
Person binPerson = null;
using(var file = System.IO.File.OpenRead("Person.bin"))
{
binPerson = ProtoBuf.Serializer.Deserialize<Person>(file);
}
- //将数据序列化后存入本地文件
- using(Stream file = File.Create(PATH))
- {
- Serializer.Serialize<List<Test>>(file, testData);
- file.Close();
- }
- //将数据从文件中读取出来,反序列化
- List<Test> fileData;
- using (Stream file = File.OpenRead(PATH))
- {
- fileData = Serializer.Deserialize<List<Test>>(file);
- }
- //Serializing Data
using (var file = File.Open(fileName, FileMode.OpenOrCreate, FileAccess.ReadWrite))
{
Serializer.Serialize<Person>(file, person);
}
//Deserializing Data
Person newPerson;
using (var file = File.OpenRead(fileName))
{
newPerson = Serializer.Deserialize<Person>(file);
}
时间: 2024-09-17 00:32:21