I have the following struct in C#
unsafe public struct control
{
public int bSetComPort;
public int iComPortIndex;
public int iBaudRa
The error you are reporting as a compile error is in fact a runtime error (an ArgumentException
). When you want to use structtobyte
to convert a control
to byte[]
you should pass the method a reference to control
, not a byte
array (byte[]
).
control ctrl = new control();
byte[] bytes = structtobyte(ctrl);