I have the following struct:
public struct TestStruct
{
public uint eventType; //4 bytes
public uint agentMode; //4 bytes
}
On using the code below
var structTest = new TestStruct();
int size = Marshal.SizeOf<TestStruct>(structTest);
It return me 8 bytes, as expected. If I change the struct to the following:
public struct TestStruct
{
public ushort extErrorCode; //2 bytes
}
It returns me 2 bytes, as expected too. The weird part comes now: if I change the struct like this:
public struct TestStruct
{
public uint eventType; // 4 bytes
public uint agentMode; // 4 bytes
public ushort extErrorCode; // 2 bytes
}
It should return me 10 bytes, right? Well, it's returning me 12 bytes! That makes no sense!
Why does this happen?