当前位置:网站首页>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

边栏推荐
- Explore the contour detection function findcontours() of OpenCV in detail with practical examples, and thoroughly understand the real role and meaning of each parameter and mode
- Vscode shortcut key (the most complete) [easy to understand]
- 想问问,证券开户有优惠吗手机开户是安全么?
- 91. (cesium chapter) cesium rocket launch simulation
- 二叉堆(一) - 原理与C实现
- C summary of knowledge points 3
- The Missing Semester
- Deep understanding of grpc part1
- MQ prevent message loss and repeated consumption
- Seckill system 03 - redis cache and distributed lock
猜你喜欢

Redis的攻击手法

Acly and metabolic diseases

Seckill system 03 - redis cache and distributed lock

Adjacency matrix undirected graph (I) - basic concepts and C language

uniapp 使用 uni-upgrade-center
![[Maui] add click events for label, image and other controls](/img/d6/7ac9632681c970ed99c9e4d3934ddc.jpg)
[Maui] add click events for label, image and other controls

Build yocto system offline for i.mx8mmini development board

The Missing Semester

Learning summary on June 29, 2022

用实际例子详细探究OpenCV的轮廓检测函数findContours(),彻底搞清每个参数、每种模式的真正作用与含义
随机推荐
今天开户今天能买股票吗?在线开户是很安全么?
研发效能度量框架解读
Dlhsoft Kanban, Kanban component of WPF
GID: open vision proposes a comprehensive detection model knowledge distillation | CVPR 2021
Comment Cao définit la décimale de dimension
Y48. Chapter III kubernetes from introduction to mastery -- pod status and probe (21)
Neo4j Chinese developer monthly - issue 202206
自定义 grpc 插件
Personnaliser le plug - in GRPC
redis中value/SortedSet
Force button homepage introduction animation
Emotion analysis based on IMDB comment data set
Theoretical basis of graph
Can I open an account today and buy stocks today? Is it safe to open an account online?
241. 为运算表达式设计优先级 : DFS 运用题
Acly and metabolic diseases
Chen Gong: Micro service, is it still so pure?
91.(cesium篇)cesium火箭发射模拟
Why does the JVM heap memory exceed 32g and pointer compression fail?
Istio, ebpf and rsocket Broker: in depth study of service grid