By default, structs in C # are implemented using [StructLayout( LayoutKind.Sequential )]for reasons basically stating that these types of objects are commonly used for COM Interop, and their fields should remain in the order in which they were defined. Classes have LayoutKind.Auto.
My question is, should I explicitly indicate my structures as [StructLayout( LayoutKind.Auto )]this will give me any default benefits? I mean, if structs are initialized on the stack , will it have any value, i.e. GC do not need to move them? It will also help when structures are initialized on the heap - i.e. Are part of some class?
source
share