How to calculate a class instance size in memory? I want to compare two class instance in size, the size that they take in ram. What should I do?
void Main()
{
var foo1 = new Foo();
foo1.A = 1;
foo1.B = "A";
foo1.C = 2;
foo1.D = "B";
var foo2 = new Foo();
foo2.A = 1;
foo2.B = "AB";
foo2.C = 2;
foo2.D = "CD";
// Get the size of foo1 & foo2 and compare them to each other.
}
class Foo
{
public int A { get; set; }
public string B { get; set; }
public int C { get; set; }
public string D { get; set; }
}