public static complex operator +(complex c1, complex c2) { complex n = new complex(); n.y = c2.y * c1.y; n.x = c1.x * n.y / c1.y + c2.x * n.y / c2.y; n.cancel(); return(n); }
static void f2() { FileStream fs = new FileStream(@"data.ser", FileMode.Open, FileAccess.Read); BinaryFormatter bf = new BinaryFormatter(); try { complex c = bf.Deserialize(fs) as complex; Console.WriteLine(c); } catch (Exception e) { Console.WriteLine(e.Message); } finally { fs.Close(); } }
static void f1() { FileStream fs = new FileStream(@"dat2.ser", FileMode.Create, FileAccess.Write); complex c = new complex(1, 3); BinaryFormatter bf = new BinaryFormatter(); try { bf.Serialize(fs, c); } catch (Exception e) { Console.WriteLine(e.Message); } finally { fs.Close(); } Console.WriteLine("done"); }