SOS:: Structure Sizes to Byte Arrays!
I need to copy a structure into a byte array so that I can send it over a
socket. But I have been having *problems*.
Here is a runthru' of what I'm doing..
I need byte alignment - so I have the attributes defined before the struct.
[StructLayout(LayoutKind.Sequential, CharSet=CharSet.Ansi, Pack=1)]
public int field1;
public int field2;
public int field3;
public int field4;
However, when I have to convert the struct into a byte stream for writing to
the socket, I cannot figure out how to convert the struct to a byte array
except by converting the object to a string and then to a byte array - this
way I get the size of the struct as 32 bytes while it should be 16 bytes.
How do I get the exact no. of bytes?!!?
Thanks and regards
Realize your limitations. Then go beyond them.