コード例 #1
0
ファイル: Form1.cs プロジェクト: aimethierry/pc4
        private void btLoadFromBinaryFile_Click(object sender, EventArgs e)
        {
            FileStream      fs = null;
            BinaryFormatter bf = null;

            try
            {
                fs  = new FileStream("../../myTest.txt", FileMode.Open, FileAccess.Read);
                bf  = new BinaryFormatter();
                bot = (BunchOfThings)(bf.Deserialize(fs));
                //listBox1.Items.Add(t.ToString());
                //for next example: C&P from below
                listBox1.Items.Add("Name is " + bot.GetName());
                listBox1.Items.Add("Number of things in it is " + Convert.ToString(bot.GetNumberOfThings()));
                foreach (Thing t in bot.GetAllThings())
                {
                    listBox1.Items.Add(t.ToString());
                }
            }
            catch (SerializationException)
            { listBox1.Items.Add("something wrong with Serialization"); }
            catch (IOException)
            { listBox1.Items.Add("something wrong with IO"); }
            finally
            {
                if (fs != null)
                {
                    fs.Close();
                }
            }

            listBox1.Items.Add("*************loading is done*********************");
        }
コード例 #2
0
ファイル: Form1.cs プロジェクト: aimethierry/pc4
 private void btCreate_Click(object sender, EventArgs e)
 {
     //t = new Thing("Flupke", 65, true);
     //for next example: C&P from below
     bot = new BunchOfThings("Sensational shelter of lost animals");
     bot.AddThing("flupke", 23, true);
     bot.AddThing("floortje", 95, false);
     bot.AddThing("blubje", 17, true);
 }