calculate how much memory an object take csharp

Code Example - calculate how much memory an object take csharp

                
                        long size = 0;
object o = new object();
using (Stream s = new MemoryStream()) {
    BinaryFormatter formatter = new BinaryFormatter();
    formatter.Serialize(s, o);
    size = s.Length;
}