Marshal.OffsetOf Method (Type, String)
Returns the field offset of the unmanaged form of the managed class.
Assembly: mscorlib (in mscorlib.dll)
- Type: System.Type
A value type or formatted reference type that specifies the managed class. You must apply the StructLayoutAttribute to the class.
- Type: System.String
The field within the t parameter.
Return ValueType: System.IntPtr
The offset, in bytes, for the fieldName parameter within the specified class that is declared by platform invoke.
OffsetOf provides the offset in terms of the unmanaged structure layout, which does not necessarily correspond to the offset of the managed structure layout. Marshaling the structure can transform the layout and alter the offset. The t parameter can be a value type or a formatted reference type (with either a sequential or explicit layout). You can obtain the size of the entire layout by using the Marshal.SizeOf method. For additional information, see Default Marshaling for Value Types.
Beginning with the .NET Framework version 2.0, OffsetOf may expose private fields.
Windows 8.1, Windows Server 2012 R2, 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.