Updated: July 2009
Indicates the physical position of fields within the unmanaged representation of a class or structure.
Namespace:
System.Runtime.InteropServices
Assembly:
mscorlib (in mscorlib.dll)
Visual Basic (Declaration)
<ComVisibleAttribute(True)> _
<AttributeUsageAttribute(AttributeTargets.Field, Inherited := False)> _
Public NotInheritable Class FieldOffsetAttribute _
Inherits Attribute
Dim instance As FieldOffsetAttribute
[ComVisibleAttribute(true)]
[AttributeUsageAttribute(AttributeTargets.Field, Inherited = false)]
public sealed class FieldOffsetAttribute : Attribute
[ComVisibleAttribute(true)]
[AttributeUsageAttribute(AttributeTargets::Field, Inherited = false)]
public ref class FieldOffsetAttribute sealed : public Attribute
public final class FieldOffsetAttribute extends Attribute
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)> Private OemId As System.UInt64
<FieldOffset(8)> Private PageSize As System.UInt64
<FieldOffset(16)> Private ActiveProcessorMask As System.UInt64
<FieldOffset(24)> Private NumberOfProcessors As System.UInt64
<FieldOffset(32)> Private ProcessorType As System.UInt64
End Class
[StructLayout(LayoutKind.Explicit)]
public class SYSTEM_INFO
{
[FieldOffset(0)] public ulong OemId;
[FieldOffset(8)] public ulong PageSize;
[FieldOffset(16)] public ulong ActiveProcessorMask;
[FieldOffset(24)] public ulong NumberOfProcessors;
[FieldOffset(32)] public ulong ProcessorType;
}
[StructLayout(LayoutKind::Explicit)]
public ref class SYSTEM_INFO
{
public:
[FieldOffset(0)]
UInt64 OemId;
[FieldOffset(8)]
UInt64 PageSize;
[FieldOffset(24)]
UInt64 ActiveProcessorMask;
[FieldOffset(32)]
UInt64 NumberOfProcessors;
[FieldOffset(40)]
UInt64 ProcessorType;
};
For a larger example, see the System.Runtime.InteropServices..::.StructLayoutAttribute class.
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 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
XNA Framework
Supported in: 3.0, 2.0, 1.0
Reference
Date | History | Reason |
|---|
July 2009
| Removed "managed" from the summary, added a link to an additional sample.. |
Content bug fix.
|