This documentation is archived and is not being maintained.

LayoutKind Enumeration

Controls the layout of an object when exported to unmanaged code.

Namespace:  System.Runtime.InteropServices
Assembly:  mscorlib (in mscorlib.dll)

public enum class LayoutKind

Member nameDescription
Supported by the .NET Compact FrameworkSupported by the XNA FrameworkSequentialThe 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.
Supported by the .NET Compact FrameworkSupported by the XNA FrameworkExplicitThe precise position of each member of an object in unmanaged memory is explicitly controlled. Each member must use the FieldOffsetAttribute to indicate the position of that field within the type.
Supported by the .NET Compact FrameworkSupported by the XNA FrameworkAutoThe 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 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 Sequential layout and a Rect structure with Explicit layout.

enum class Bool
   False = 0,

value struct Point
   int x;
   int y;

value struct Rect

   int left;

   int top;

   int right;

   int bottom;

ref class LibWrapper

   static Bool PtInRect( Rect * r, Point p );

int main()
      Bool bPointInRect = (Bool)0;
      Rect myRect = Rect(  );
      myRect.left = 10;
      myRect.right = 100; = 10;
      myRect.bottom = 100;
      Point myPoint = Point(  );
      myPoint.x = 50;
      myPoint.y = 50;
      bPointInRect = LibWrapper::PtInRect(  &myRect, myPoint );
      if ( bPointInRect == Bool::True )
            Console::WriteLine( "Point lies within the Rect" );
            Console::WriteLine( "Point did not lie within the Rect" );
   catch ( Exception^ e ) 
      Console::WriteLine( "Exception : {0}", e->Message );


Windows 7, Windows Vista, Windows XP SP2, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP Starter Edition, Windows Server 2008 R2, Windows Server 2008, Windows Server 2003, Windows Server 2000 SP4, Windows Millennium Edition, Windows 98, Windows CE, Windows Mobile for Smartphone, Windows Mobile for Pocket PC, Xbox 360, Zune

The .NET Framework and .NET Compact Framework do not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

.NET Framework

Supported in: 3.5, 3.0, 2.0, 1.1, 1.0

.NET Compact Framework

Supported in: 3.5, 2.0, 1.0

XNA Framework

Supported in: 3.0, 2.0, 1.0