views:

16

answers:

0

Assume that we have two C# structures:

    [Serializable, StructLayout(LayoutKind.Sequential, Pack = 1)]
    public struct ByteStructure 
    {
        public byte byte0;
        public byte byte1;
        public byte byte2;
        public byte byte3;
        public byte byte4;
        public byte byte5;
        public byte byte6;
        public byte byte7;
        public byte byte8;
        public byte byte9;
        public byte byteA;
        public byte byteB;
        public byte byteC;
        public byte byteD;
        public byte byteE;
        public byte byteF;
     }

     [Serializable, StructLayout(LayoutKind.Sequential, Pack = 1)]
     public struct IntStructure
     {
        public int i0;
        public int i1;
        public int i2;
        public int i3;
      }

      ByteStructure bs;
      IntStructure is;
...

How to transform one structure to another like in C++:

is = (IntStructure)bs;

or

bs = (ByteStructure)is;