public static void F2() { FileStream fs = new FileStream("ComNum.xml", FileMode.OpenOrCreate, FileAccess.ReadWrite); XmlSerializer xs = new XmlSerializer(typeof(ComNum)); ComNum ComplexNumbers = xs.Deserialize(fs) as ComNum; //deserializing Console.WriteLine(ComplexNumbers.numbers[0]); //output on the console Console.WriteLine(ComplexNumbers.numbers[1]); }
public static void F1() { ComNum ComplexNumbers = new ComNum(); //creating the instance of the class ComNum ComplexNumber number1 = new ComplexNumber(7, 2); //creating the instance of the class ComplexNumber ComplexNumber number2 = new ComplexNumber(4, 3); ComplexNumbers.numbers.Add(number1); //adding into the list ComplexNumbers.numbers.Add(number2); FileStream fs = new FileStream("ComNum.xml", FileMode.OpenOrCreate, FileAccess.ReadWrite); //provide a stream for a file XmlSerializer xs = new XmlSerializer(typeof(ComNum)); // create an instance of the XmlSerializer class and specify the type of object to serialize xs.Serialize(fs, ComplexNumbers); //serializing an instance of the class ComNum fs.Close(); // close the stream }