public struct TestStruct
{
public int first;
public int second;
public int third;
}
Marshal.SizeOf returns 12, which I assume, because ints are 4 bytes each. If I changed the third to double instead of int, I would expect Marshal.SizeOf to return 16. This is so. But if I added a fourth, which was double, Marshal.SizeOf would return 24 when I expect 20. I could have 10 integers, and in the end, each would have 4 bytes each. But if I add a double number after three ints, the size is not as expected.
public struct TestStruct
{
public int first;
public int second;
public int third;
}
public struct TestStruct
{
public int first;
public int second;
public double third;
}
public struct TestStruct
{
public int first;
public int second;
public double third;
public int fourth;
}
Where did my thinking lead me astray?
source
share