static void

Serialization

//data must be [Serializable]
MyObjectType data = new MyObjectType();
MemoryStream stm = new MemoryStream();
// Serialize
IFormatter f = new BinaryFormatter(); //XmlSerializer, SoapFormatter
f.Serialize(stm, data);
// DeSerialize
stm.Seek(0, SeekOrigin.Begin);
IFormatter ds = new BinaryFormatter();
data = (MyObjectType)ds.Deserialize(stm);

//xmlserializer
var serializer = new XmlSerializer(typeof(Product));
using (var sw = new StringWriter())
{
    serializer.Serialize(sw, product);
    var xml = sw.ToString();
}
//datacontract serializer
var dcs = new DataContractSerializer(typeof(Product));
using (var sw = new StringWriter())
{
    using (var xw = XmlWriter.Create(sw))
    {
        dcs.WriteObject(xw, product);
    }
    var xml = sw.ToString();
}