惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

人人都是产品经理
人人都是产品经理
aimingoo的专栏
aimingoo的专栏
Y
Y Combinator Blog
B
Blog
D
Docker
C
Check Point Blog
A
About on SuperTechFans
云风的 BLOG
云风的 BLOG
F
Fortinet All Blogs
Stack Overflow Blog
Stack Overflow Blog
Recent Announcements
Recent Announcements
MongoDB | Blog
MongoDB | Blog
WordPress大学
WordPress大学
Jina AI
Jina AI
罗磊的独立博客
月光博客
月光博客
博客园 - Franky
L
LangChain Blog
H
Help Net Security
Google DeepMind News
Google DeepMind News
Microsoft Security Blog
Microsoft Security Blog
小众软件
小众软件
T
Tailwind CSS Blog
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻

博客园 - UnseenstoneX

《打砖块创作家》隐私政策 打砖块创作家《小游戏隐私保护指引》 python 常用数据结构 Python 基本语法 地形遇到几个问题 TArray数组 UE问题分部解决 UE寻找Actor UE对话框 ShadowCaster 代码 C#读写csv文件 优化相关 unity 打开文件夹并鼠标选中某文件 Json解析 C# winform中 选择文件和保存文件 Unity与Android交互实现 一个将数据均匀分段1,2,5的随写 C# 持续序列化对象追加到文件的方法 读写文件
C#二进制序列化和反序列化
UnseenstoneX · 2018-06-06 · via 博客园 - UnseenstoneX
public class WRSerializable
{
    public static void SerializeToFile<T>(T _description, string _filePath)
    {
        using (Stream fStream = File.Create(_filePath))
        {
            BinaryFormatter binFormat = new BinaryFormatter();//创建二进制序列化器
            binFormat.Serialize(fStream, _description);
        }
    }

    public static void DeserializeFromFile<T>(ref T _description, string _filePath)
    {
        using (FileStream fileStream = File.OpenRead(_filePath))
        {
            BinaryFormatter binaryFormatter = new BinaryFormatter();
            _description = (T)binaryFormatter.Deserialize(fileStream);
        }
    }
    // public static void SerializeToFile<T>(T _description, string _filePath)
    // {
    //     FileStream fs = new FileStream(_filePath, FileMode.OpenOrCreate);
    //     BinaryFormatter bf = new BinaryFormatter();
    //     bf.Serialize(fs, _description);
    //     fs.Close();
    // }

    // public static void DeserializeFromFile<T>(ref T _description, string _filePath)
    // {
    //     FileStream fs = new FileStream(_filePath, FileMode.Open);
    //     BinaryFormatter bf = new BinaryFormatter();
    //     _description = (T)bf.Deserialize(fs);
    //     fs.Close();
    // }
}

filePath示例“mData.bin”