[FieldOffset(24)]
public fixed Int32 myArray[4];
As far as I understand it should be an int array. But I’m not sure. I stumbled over this while looking over a code base which is not mine. It seems there is worked a lot with pointers.
2
A fixed
array is not a regular managed array, think of it instead as 4 int
values stored next to each other. Or a C array, if you know C.
The FieldOffset
attribute tells the marshaller where the original data is stored during marshalling, ie during P/Invoke when you use the structure, again to reach parity with C struct
definitions.
1
[FieldOffset(24)] public fixed Int32 myArray[4];
Before elaborating you might need to learn below:
Struct
You might need to acquire some knowledge regarding `struct` in dotnet. basically `struct` in dotnet is a value type. that is typically used to encapsulate small groups of related variables together with each other.
FieldOffset(24)
[FieldOffset(24)]
declares that myArray
field starts at offset 24 bytes within the containing struct
fixed
The fixed
keyword in dotnet is used primarily in unsafe code contexts to interact with unmanaged memory. In your case myArray
is an array of four element Int32
elements.