示例#1
0
        private static void F2()                                                              //method of deserializing
        {
            FileStream    fs = new FileStream("complex.txt", FileMode.Open, FileAccess.Read); // new filestream to open and read file
            XmlSerializer xs = new XmlSerializer(typeof(ComplNum));                           //new serializer
            ComplNum      CN = xs.Deserialize(fs) as ComplNum;                                // new example of class will be taken from deserializing of existing file

            fs.Close();                                                                       //close filestream
            CN.PrintInfo();                                                                   // calling method of printing
        }
示例#2
0
        private static void F1()           // method of serializing
        {
            ComplNum num = new ComplNum(); // new exapmle of class

            num.a = 12;
            num.b = 10;
            num.PrintInfo();
            FileStream    fs = new FileStream("complex.txt", FileMode.Create, FileAccess.Write); // new filestream to creat file
            XmlSerializer xs = new XmlSerializer(typeof(ComplNum));                              //new serializer

            xs.Serialize(fs, num);                                                               //serializing our example of class
            fs.Close();                                                                          //close filestream
        }