示例#1
0
文件: Program.cs 项目: baudynbay/PP2
        static void Main(string[] args)
        {
            /* int a, b;
             * a = int.Parse(Console.ReadLine());
             * b = int.Parse(Console.ReadLine());
             *
             * ComplexN one = new ComplexN(a,b);
             *
             * Console.WriteLine(one.ToString());
             *
             * XmlSerializer number = new XmlSerializer(typeof(ComplexN));
             * using (TextWriter writer = new StreamWriter(@"Xml.xml"))
             * {
             *   number.Serialize(writer, one);
             *   writer.Close();
             * }*/

            XmlSerializer deserializer = new XmlSerializer(typeof(ComplexN));

            using (TextReader reader = new StreamReader(@"Xml.xml"))
            {
                object   obj = deserializer.Deserialize(reader);
                ComplexN two = (ComplexN)obj;
                reader.Close();
                Console.WriteLine(two);
            }
        }
示例#2
0
        private static void F2()
        {
            FileStream    fs = new FileStream("ComplexNumber.txt", FileMode.Open, FileAccess.Read);
            XmlSerializer xs = new XmlSerializer(typeof(ComplexN));
            ComplexN      t  = xs.Deserialize(fs) as ComplexN;

            Console.WriteLine($"{t.A}  {t.B}");
            fs.Close();
        }
示例#3
0
        private static void F1()
        {
            ComplexN l = new ComplexN
            {
                A = 56,
                B = 5.4
            };
            FileStream    fs = new FileStream("ComplexNumber.txt", FileMode.OpenOrCreate, FileAccess.Write);
            XmlSerializer xs = new XmlSerializer(typeof(ComplexN));

            xs.Serialize(fs, l);

            fs.Close();
        }