I have a structure definition as follows:
public struct champ
{
public uint mem1;
public byte[] mem2;
public champ(int x)
{
mem1 = x;
mem2 = new byte[15];
}
}
After creating an object
champ sample = new champ (2);
Applying Marshal.SizeOf(sample) returns 4+4 = 8 instead of 4 +15. Why?
If it was a class, I can understand that logic because the second member is a pointer occupying 4 bytes which points to the byte array mem2 on the heap. Why is this happening for a struct?