static void SaveComplex(Complex a, Complex b, Complex c, Complex d) { XmlSerializer save = new XmlSerializer(typeof(SerializedData)); FileStream fs = new FileStream("save.xml", FileMode.OpenOrCreate, FileAccess.ReadWrite); List <Complex> list = new List <Complex>(); list.Add(a); list.Add(b); list.Add(c); list.Add(d); SerializedData s = new SerializedData(); s.numbers = list; save.Serialize(fs, s); fs.Close(); }
static void OpenComplex() { try { XmlSerializer open = new XmlSerializer(typeof(SerializedData)); FileStream fs = new FileStream("save.xml", FileMode.OpenOrCreate, FileAccess.ReadWrite); SerializedData sd = open.Deserialize(fs) as SerializedData; foreach (Complex p in sd.numbers) { Console.WriteLine(p); } } catch (Exception e) { Console.WriteLine(e); } }