I have this struct in C#, I wanted to convert the struct to a byte[] so I thought I’d use Marshal for that.
The first thing I did was to get the size in memory of the struct, given that it has 2 int and a long I expected Marshal.SizeOf(myStruct); to return 16 but instead it returned 4.
public struct ConnectionRequest
{
public const long protocolId = 0x41727101980;
public const int action = 0;
public int transactionId;
}
This struct, however, returned the expected size of 16, which makes me think that the const members in the first struct aren’t really IN the struct.
public struct ConnectionRequest
{
public long protocolId;
public int action;
public int transactionId;
}
I assume that the dotnet compiler must be doing some clever magic with the const members but how can they not be in the struct?
Do you know why this happens?
Thanks