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

边栏推荐
- About keil compiler, "file has been changed outside the editor, reload?" Solutions for
- 谈思生物直播—GENOVIS张洪妍抗体特异性酶切技术助力抗体药物结构表征
- Brief explanation of the working principle, usage scenarios and importance of fingerprint browser
- Value/set in redis
- Raspberry pie 4B installation tensorflow2.0[easy to understand]
- 构建外部模块(Building External Modules)
- 91.(cesium篇)cesium火箭发射模拟
- JS date format conversion method
- Use set_ Handler filters out specific SystemC wrapping & error messages
- Redis的攻击手法
猜你喜欢
随机推荐
Harbor webhook from principle to construction
Redis启动与库进入
Value/string in redis
消息队列之监控退款任务批处理过程
Kernel synchronization mechanism
Impressive bug summary (continuously updated)
ACLY与代谢性疾病
Abbirb120 industrial robot mechanical zero position
用实际例子详细探究OpenCV的轮廓检测函数findContours(),彻底搞清每个参数、每种模式的真正作用与含义
CAD如何设置标注小数位
Summary of JFrame knowledge points 1
想问问,证券开户有优惠吗手机开户是安全么?
Seckill system 03 - redis cache and distributed lock
Xiaomi mobile phone unlocking BL tutorial
Redis common sense
Consolidate -c operator
区间乘积的因子数之和——前缀和思想+定一移二
redis中value/set
Uniapp uses uni upgrade Center
Personnaliser le plug - in GRPC









