How can I declare structure with a fixed size array in it?
I found solution, but it only works for primitive data-types. I need my array to be of type MyStruct
.
So how can I declare a struct with an array of other structs in it?
ex.
unsafe struct Struct1{
fixed int arrayInt[100]; // works properly
fixed Struct2 arrayStruct[100]; //not compile
}
My colleague found the working way to do this. I think it`s right way.
[StructLayout(LayoutKind.Sequential)]
public struct Struct1
{
[MarshalAs(UnmanagedType.ByValArray, SizeConst = sizeOfarray)]
private Struct2[] arrayStruct;
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With