I noticed that there are many places we have something like this:
[StructLayout(LayoutKind.Sequential, Pack = 1)]
public class E2H_LANEFIND_DATA_T
{
....
}
class definition with StructLayout
. Is that ok or StructLayout
is only for struct
?
The documentation clearly states:
You can apply this attribute to classes or structures.
Typically, the common language runtime controls the physical layout of the data fields of a class or structure in managed memory. However, if you want to arrange the class or structure needs in a certain way, you can use StructLayoutAttribute. Explicit control of a class layout is important if the class is to be passed to unmanaged code that expects a specific layout.
Emphasis was mine.
The main consideration to make in this situation is whether you want your instances to be passed by value or by reference, in which case you would respectively use a struct or a class.
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