当前位置:网站首页>C serialization simple experiment
C serialization simple experiment
2022-07-01 12:03:00 【The development of Science - just reading the code written by n】
1. Summary
Sometimes , Some variables will be lost due to program interruption . Can serialization be used to solve this problem , So there was this experiment .
2. Code
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Runtime.Serialization;
using System.Runtime.Serialization.Formatters.Binary;
using System.Text;
using System.Threading.Tasks;
namespace serialize
{
[Serializable]
class A {
int a = 1;
string b = "b";
public int fun() {
return a + 2;
}
}
class Program
{
static void Main(string[] args)
{
Console.WriteLine(" serialize ");
A a = new A();
// Objects for serialization and deserialization
IFormatter serializer = new BinaryFormatter();
// Start serializing
FileStream saveFile = new FileStream("Test.txt", FileMode.Create, FileAccess.Write);
serializer.Serialize(saveFile, a);
saveFile.Close();
// Deserialization
FileStream loadFile = new FileStream("Test.txt", FileMode.Open, FileAccess.Read);
A a2 = serializer.Deserialize(loadFile) as A;
int b = a2.fun();
Console.ReadKey();
}
}
}
3. experimental result

边栏推荐
猜你喜欢

研发效能度量框架解读

强大、好用、适合程序员/软件开发者的专业编辑器/笔记软件综合评测和全面推荐

Use set_ Handler filters out specific SystemC wrapping & error messages

NOV Schedule for . Net to display and organize appointments and recurring events

Harbor webhook from principle to construction

Build yocto system offline for i.mx8mmini development board

Mechanism and type of CPU context switch

Deep understanding of grpc part1

The Missing Semester

Huawei HMS core joins hands with hypergraph to inject new momentum into 3D GIS
随机推荐
8 best practices to protect your IAC security!
消息队列之监控退款任务批处理过程
华为HMS Core携手超图为三维GIS注入新动能
Emotion analysis based on IMDB comment data set
Consolidate -c operator
CAD如何設置標注小數比特
C summary of knowledge points 3
指纹浏览器工作原理、使用场景以及重要性简单讲解
Harbor webhook from principle to construction
Computer graduation project asp Net hotel room management system VS development SQLSERVER database web structure c programming computer web page source code project
构建外部模块(Building External Modules)
Implementation of address book management system with C language
2022/6/30学习总结
Compile and debug net6 source code
用实际例子详细探究OpenCV的轮廓检测函数findContours(),彻底搞清每个参数、每种模式的真正作用与含义
USB peripheral driver - cable connect/disconnect
2022/6/28学习总结
Comment Nike a - t - il dominé la première place toute l'année? Voici les derniers résultats financiers.
Activity workflow engine
力扣首页简介动画