static void Save(ComplexNumbers cn, string filename) { FileStream fs = new FileStream(filename, FileMode.Create, FileAccess.Write); XmlSerializer xml = new XmlSerializer(typeof(ComplexNumbers)); xml.Serialize(fs, cn); fs.Close(); }
static ComplexNumbers Load(string filename) { FileStream fs = new FileStream(filename, FileMode.Open, FileAccess.Read); XmlSerializer xml = new XmlSerializer(typeof(ComplexNumbers)); ComplexNumbers cn = xml.Deserialize(fs) as ComplexNumbers; fs.Close(); return(cn); }
static void Main(string[] args) { string[] s = Console.ReadLine().Split(); string filename = "saveComplexNumbers.xml"; ComplexNumbers ab = new ComplexNumbers(int.Parse(s[0]), int.Parse(s[1])); Save(ab, filename); ComplexNumbers cn = Load(filename); Console.WriteLine(cn.GetData()); }
public static void F1() { ComplexNumbers cn = new ComplexNumbers(); //according to the characteristics of class Mark we create ; cn.PrintInfo(); //this is a solution; cn.PrintFormula(); //write in console formula FileStream fs = new FileStream("cn.txt", FileMode.Create, FileAccess.Write); XmlSerializer xs = new XmlSerializer(typeof(ComplexNumbers)); xs.Serialize(fs, cn);//serializing-it's to save ur condition to txt or xml file to network with others in the internet or e.t.c fs.Close(); }