Marshal.OffsetOf Marshal.OffsetOf Marshal.OffsetOf Marshal.OffsetOf Method

Definition

Overloads

OffsetOf(Type, String) OffsetOf(Type, String) OffsetOf(Type, String) OffsetOf(Type, String)

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

OffsetOf<T>(String) OffsetOf<T>(String) OffsetOf<T>(String) OffsetOf<T>(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.

OffsetOf(Type, String) OffsetOf(Type, String) OffsetOf(Type, String) OffsetOf(Type, String)

Warning

This API is now obsolete.

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

public:
 static IntPtr OffsetOf(Type ^ t, System::String ^ fieldName);
[System.Obsolete("OffsetOf(Type, string) may be unavailable in future releases. Instead, use OffsetOf<T>(string). For more info, go to http://go.microsoft.com/fwlink/?LinkID=296511")]
public static IntPtr OffsetOf (Type t, string fieldName);
static member OffsetOf : Type * string -> nativeint
Public Shared Function OffsetOf (t As Type, fieldName As String) As IntPtr
Parameters
t
Type Type Type Type

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

fieldName
String String String String

The field within the t parameter.

Returns

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

Exceptions

The class cannot be exported as a structure or the field is nonpublic. Beginning with the .NET Framework version 2.0, the field may be private.

Remarks

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.

Note

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

See Also

OffsetOf<T>(String) OffsetOf<T>(String) OffsetOf<T>(String) OffsetOf<T>(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.

public:
generic <typename T>
 static IntPtr OffsetOf(System::String ^ fieldName);
public static IntPtr OffsetOf<T> (string fieldName);
static member OffsetOf : string -> nativeint
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
String String String String

The name of the field in the T type.

Returns

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

Remarks

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

Note

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

See Also

Applies to