コード例 #1
0
        static public bool Save(string filename, StudentList obj)
        {
            try
            {
                //MemoryStream ms = new MemoryStream();
                FileStream      ms   = File.Create(filename);
                BinaryFormatter binF = new BinaryFormatter();
                binF.Serialize(ms, obj);

                return(true);
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
                return(false);
            }
        }
コード例 #2
0
        static public bool Load(string filename, ref StudentList obj)
        {
            try
            {
                FileStream      ms   = File.OpenRead(filename);
                BinaryFormatter binF = new BinaryFormatter();


                ms.Seek(0, SeekOrigin.Begin);
                obj = binF.Deserialize(ms) as StudentList;
                return(true);
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
                return(false);
            }
        }