示例代码如下:

List<int> notOutput_GcIds = new List<int>();
string dataFileName = @".\Config\notOutput_GcIds.dat";

// 保存没有输出的 GC 的 ID 值到文件 dataFileName
private void Serialize_NotOutput_GcIds()
{
    string configFileName = dataFileName;
    FileStream stream = new FileStream(configFileName, FileMode.Create);
    BinaryFormatter bFormat = new BinaryFormatter();
    bFormat.Serialize(stream, notOutput_GcIds);
    stream.Close();
}

// 从文件 dataFileName 加载没有输出的 GC 的 ID 值
private void Deserialize_NotOutput_GcIds()
{
    string configFileName = dataFileName;

    if (!File.Exists(configFileName)) { return; }

    FileStream stream = new FileStream(configFileName, FileMode.Open);
    BinaryFormatter bFormat = new BinaryFormatter();
    notOutput_GcIds = (List<int>)bFormat.Deserialize(stream);
    stream.Close();
}

 

  

 

posted on 2021-01-12 14:41  青叶煮酒  阅读(100)  评论(0编辑  收藏  举报