Export (0) Print
Expand All

Marshal.OffsetOf(Of T) Method (String)

[Supported in the .NET Framework 4.5.1 and later versions]

Returns the field offset of the unmanaged form of a specified managed class.

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

'Declaration
Public Shared Function OffsetOf(Of T) ( _
	fieldName As String _
) As IntPtr

Type Parameters

T

A managed value type or formatted reference type. You must apply the StructLayoutAttribute attribute to the class.

Parameters

fieldName
Type: System.String

The name of the field in the T type.

Return Value

Type: System.IntPtr
The offset, in bytes, for the fieldName parameter within the specified class that is declared by platform invoke.

OffsetOf(Of T)(String) 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 generic type 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 SizeOf(Of T)(T) method. For additional information, see Default Marshaling for Value Types.

NoteNote

Beginning with the .NET Framework version 2.0, OffsetOf may expose private fields.

.NET Framework

Supported in: 4.6, 4.5.1

Supported in: Windows Phone 8.1

Windows Phone 8.1

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

Show:
© 2014 Microsoft