Ask Learn
Preview
Ask Learn is an AI assistant that can answer questions, clarify concepts, and define terms using trusted Microsoft documentation.
Please sign in to use Ask Learn.
Sign inThis browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
Note
Access to this page requires authorization. You can try signing in or changing directories.
Access to this page requires authorization. You can try changing directories.
Important
Some information relates to prerelease product that may be substantially modified before it’s released. Microsoft makes no warranties, express or implied, with respect to the information provided here.
OffsetOf(Type, String) |
Obsolete.
Returns the field offset of the unmanaged form of the managed class. |
OffsetOf<T>(String) |
Returns the field offset of the unmanaged form of a specified managed class. |
Caution
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
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);
public static IntPtr OffsetOf(Type t, 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")>]
static member OffsetOf : Type * string -> nativeint
static member OffsetOf : Type * string -> nativeint
Public Shared Function OffsetOf (t As Type, fieldName As String) As IntPtr
A value type or formatted reference type that specifies the managed class. You must apply the StructLayoutAttribute to the class.
The field within the t
parameter.
nativeint
The offset, in bytes, for the fieldName
parameter within the specified class that is declared by platform invoke.
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.
The t
parameter is null
.
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.
Product | Versions (Obsolete) |
---|---|
.NET | Core 1.1, Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9, 10 (Core 1.0) |
.NET Framework | 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1 |
.NET Standard | 1.1, 2.0, 2.1 (1.2, 1.3, 1.4, 1.5, 1.6) |
UWP | (10.0) |
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
A managed value type or formatted reference type. You must apply the StructLayoutAttribute attribute to the class.
The name of the field in the T
type.
nativeint
The offset, in bytes, for the fieldName
parameter within the specified class that is declared by platform invoke.
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.
Product | Versions |
---|---|
.NET | Core 1.0, Core 1.1, Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9, 10 |
.NET Framework | 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1 |
.NET Standard | 1.2, 1.3, 1.4, 1.5, 1.6, 2.0, 2.1 |
UWP | 10.0 |
.NET feedback
.NET is an open source project. Select a link to provide feedback:
Ask Learn is an AI assistant that can answer questions, clarify concepts, and define terms using trusted Microsoft documentation.
Please sign in to use Ask Learn.
Sign in