Original question: C# array within a struct
Fixed size buffers work for some intrinsic data types(bool,byte,short,int,..), but when needing to define an array of struct, within a struct, I've so far failed to be clever enough.
In the following, assume 'recordLayout' is a struct containing 18 fields, including some arrays of simple types, which were solved by unsafe and fixed size buffers. Next I'm needing to populate the following structure (containing an array of struct) from the binary file.
[StructLayout(LayoutKind.Sequential,Pack=1)]
unsafe struct dataBlock { // 2048 bytes
fixed ushort junk[5];
fixed recordLayout records[22]; // doesnt work of course, data type constrained
fixed byte filler[14];
}
I've tried creating an explicit LayoutKind struct that maps a fixed byte array to the record array, but immediately bump into not being allowed to do that.