关于c#序列化和反序列化(二进制)

序列化

 

 public void SerizeFile(Hashtable m_collect)
        {
            FileStream fs = new FileStream("Myfile.data", FileMode.OpenOrCreate, FileAccess.ReadWrite, FileShare.ReadWrite);
            BinaryFormatter bf = new BinaryFormatter();
            bf.Serialize(fs, m_collect);
            fs.Close();
        }

 反序列化

 

public Hashtable USerizeFile(string filename)
        {
            FileStream fs = new FileStream(filename, FileMode.OpenOrCreate);
            BinaryFormatter bf = new BinaryFormatter();
            Hashtable clone = null;
            if (fs.Length > 0)
            {
                clone = (Hashtable)bf.Deserialize(fs);
            }
            fs.Close();
            return clone;
        }

你可能感兴趣的:(C++,c,C#)