How to find the size of Object and show it on screen [closed]

You can get your object size like this:

public double GetObjectSize(Object Obj)
{
     using (var m = new System.IO.MemoryStream())
     {
     System.Runtime.Serialization.Formatters.Binary.BinaryFormatter b = new
     System.Runtime.Serialization.Formatters.Binary.BinaryFormatter();
     b.Serialize(m, Obj);
     double size = Convert.ToDouble(m.Length);
     return size;
    }
}

But consider that not all objects are serializable. And it will not serialize nested objects too deep.

Leave a Comment