This documentation is archived and is not being maintained.

FieldOffsetAttribute Class

Indicates the physical position of fields within the unmanaged representation of a class or structure.

For a list of all members of this type, see FieldOffsetAttribute Members.


[Visual Basic]
NotInheritable Public Class FieldOffsetAttribute
   Inherits Attribute
public sealed class FieldOffsetAttribute : Attribute
public __gc __sealed class FieldOffsetAttribute : public Attribute
class FieldOffsetAttribute extends Attribute

Thread Safety

Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.


You can apply this attribute to fields.

This attribute is used when System.Runtime.InteropServices.StructLayoutAttribute, with LayoutKind.Explicit passed to its constructor, is applied to a class or structure to specify the offset of each non- static (Shared in Visual Basic) or constant member within the unmanaged representation of that class or structure. The attribute has no affect on the managed layout of the members of the type.


[Visual Basic, C#, C++] The following example demonstrates how to apply the FieldOffsetAttribute to members of a class with an explicit layout.

[Visual Basic] 
<StructLayout(LayoutKind.Explicit)> _
Public Class SYSTEM_INFO
    <FieldOffset(0)> Private OemId As System.UInt64
    <FieldOffset(4)> Private PageSize As System.UInt64
    <FieldOffset(16)> Private ActiveProcessorMask As System.UInt64
    <FieldOffset(20)> Private NumberOfProcessors As System.UInt64
    <FieldOffset(24)> Private ProcessorType As System.UInt64
End Class

public class SYSTEM_INFO
[FieldOffset(0)] public ulong OemId;
[FieldOffset(4)] public ulong PageSize;
[FieldOffset(16)] public ulong ActiveProcessorMask;
[FieldOffset(20)] public ulong NumberOfProcessors;
[FieldOffset(24)] public ulong ProcessorType;

public __gc class SYSTEM_INFO
[FieldOffset(0)] UInt64 OemId;
[FieldOffset(4)] UInt64 PageSize;
[FieldOffset(16)] UInt64 ActiveProcessorMask;
[FieldOffset(20)] UInt64 NumberOfProcessors;
[FieldOffset(24)] UInt64 ProcessorType;

[JScript] No example is available for JScript. To view a Visual Basic, C#, or C++ example, click the Language Filter button Language Filter in the upper-left corner of the page.


Namespace: System.Runtime.InteropServices

Platforms: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 family

Assembly: Mscorlib (in Mscorlib.dll)

See Also

FieldOffsetAttribute Members | System.Runtime.InteropServices Namespace | StructLayoutAttribute | LayoutKind