// Collection of code snippets by Arne Vajhøj // (likely posted to comp.os.vms/INFO-VAX, INFO-TPU, MACRO32, eksperten.dk, newz.dk, LinkedIn or other place sometime between 1990 and now) using System; using System.IO; using System.Runtime.Serialization.Formatters.Soap; namespace E { [Serializable] public class Data { private int z; /* public Data() : this(0) { } */ public Data(int z) { this.z = z; } public int Iv { get; set; } public string Sv { get; set; } public override string ToString() { return "[" + z + "," + Iv + "," + Sv + "]"; } } public class Program { public static void Main(string[] args) { Data d = new Data(777); d.Iv = 123; d.Sv = "ABC"; Console.WriteLine(d); SoapFormatter soapser = new SoapFormatter(); using(Stream outs = new FileStream(@"C:\d.soap", FileMode.Create, FileAccess.Write)) { soapser.Serialize(outs, d); } using(Stream ins = new FileStream(@"C:\d.soap", FileMode.Open, FileAccess.Read)) { Data dbin = (Data)soapser.Deserialize(ins); Console.WriteLine(dbin); } } } }