Export (0) Print
Expand All

FieldOffsetAttribute Class

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

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

[AttributeUsageAttribute(AttributeTargets.Field, Inherited=false)] 
[ComVisibleAttribute(true)] 
public sealed class FieldOffsetAttribute : Attribute
/** @attribute AttributeUsageAttribute(AttributeTargets.Field, Inherited=false) */ 
/** @attribute ComVisibleAttribute(true) */ 
public final class FieldOffsetAttribute extends Attribute
AttributeUsageAttribute(AttributeTargets.Field, Inherited=false) 
ComVisibleAttribute(true) 
public final class FieldOffsetAttribute extends Attribute
Not applicable.

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 or constant member within the unmanaged representation of that class or structure.

The following example demonstrates how to apply the FieldOffsetAttribute to members of a class with an explicit layout.

[StructLayout(LayoutKind.Explicit)]
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;
}

/** @attribute StructLayout(LayoutKind.Explicit)
 */
public class SYSTEM_INFO
{   
    /** @attribute FieldOffset(0)
     */
    public long oemId;
    
    /** @attribute FieldOffset(4)
     */
    public long pageSize;
    
    /** @attribute FieldOffset(16)
     */
    public long activeProcessorMask;
   
    /** @attribute FieldOffset(20)
     */
    public long numberOfProcessors;
    
    /** @attribute FieldOffset(24)
     */
    public long processorType;
   
} //SYSTEM_INFO

System.Object
   System.Attribute
    System.Runtime.InteropServices.FieldOffsetAttribute

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

Windows 98, Windows Server 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile for Pocket PC, Windows Mobile for Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

The Microsoft .NET Framework 3.0 is supported on Windows Vista, Microsoft Windows XP SP2, and Windows Server 2003 SP1.

.NET Framework

Supported in: 3.0, 2.0, 1.1, 1.0

.NET Compact Framework

Supported in: 2.0

XNA Framework

Supported in: 1.0

Community Additions

ADD
Show:
© 2015 Microsoft