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); } }
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(); }
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(); }