Controls the layout of an object when exported to unmanaged code.
Assembly: mscorlib (in mscorlib.dll)
|The members of the object are laid out sequentially, in the order in which they appear when exported to unmanaged memory. The members are laid out according to the packing specified in StructLayoutAttribute.Pack, and can be noncontiguous.|
|The precise position of each member of an object in unmanaged memory is explicitly controlled, subject to the setting of the StructLayoutAttribute.Pack field. Each member must use the FieldOffsetAttribute to indicate the position of that field within the type.|
|The runtime automatically chooses an appropriate layout for the members of an object in unmanaged memory. Objects defined with this enumeration member cannot be exposed outside of managed code. Attempting to do so generates an exception.|
This enumeration is used with StructLayoutAttribute. The common language runtime uses the Auto layout value by default. To reduce layout-related problems associated with the Auto value, C#, Visual Basic, and C++ compilers specify Sequential layout for value types.
The StructLayoutAttribute.Pack field controls the alignment of data fields, and thus affects the layout regardless of the value you specify. By default, the value of Pack is 0, which indicates the default packing size for the current platform. For example, when you use the Explicit layout value and specify field alignments on byte boundaries, you must set Pack to 1 to get the desired result.
The following example shows the managed declaration of the PtInRect function, which checks whether a point lies within a rectangle, and defines a Point structure with layout and a Rect structure with layout.
Windows 8, Windows Server 2012, Windows 7, Windows Vista SP2, Windows Server 2008 (Server Core Role not supported), Windows Server 2008 R2 (Server Core Role supported with SP1 or later; Itanium not supported)
The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.