How to convert a structure to a byte array in C#?

前端 未结 14 1042
难免孤独
难免孤独 2020-11-22 09:59

How do I convert a structure to a byte array in C#?

I have defined a structure like this:

public struct CIFSPacket
{
    public uint protocolIdentifi         


        
14条回答
  •  [愿得一人]
    2020-11-22 10:30

    I would take a look at the BinaryReader and BinaryWriter classes. I recently had to serialize data to a byte array (and back) and only found these classes after I'd basically rewritten them myself.

    http://msdn.microsoft.com/en-us/library/system.io.binarywriter.aspx

    There is a good example on that page too.

提交回复
热议问题