通过


Marshal.OffsetOf 方法

定义

重载

名称 说明
OffsetOf(Type, String)
已过时.

返回托管类的非托管形式的字段偏移量。

OffsetOf<T>(String)

返回指定托管类的非托管形式的字段偏移量。

OffsetOf(Type, String)

Source:
Marshal.CoreCLR.cs
Source:
Marshal.CoreCLR.cs
Source:
Marshal.CoreCLR.cs
Source:
Marshal.CoreCLR.cs
Source:
Marshal.CoreCLR.cs

注意

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, 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

参数

t
Type

指定托管类的值类型或格式化引用类型。 必须向类应用 StructLayoutAttribute 该类。

fieldName
String

参数中的 t 字段。

返回

IntPtr

nativeint

由平台调用声明的指定类中的参数的偏移量(以字节为单位 fieldName )。

属性

例外

不能将类导出为结构,或者该字段是非公共的。该字段可能是私有的。

参数 tnull.

注解

OffsetOf 提供非托管结构布局的偏移量,这不一定与托管结构布局的偏移量相对应。 封送结构可以转换布局并更改偏移量。 参数 t 可以是值类型或格式化引用类型(具有顺序或显式布局)。 可以使用该方法获取整个布局 Marshal.SizeOf 的大小。

注释

OffsetOf 可能会公开专用字段。

另请参阅

适用于

OffsetOf<T>(String)

Source:
Marshal.cs
Source:
Marshal.cs
Source:
Marshal.cs
Source:
Marshal.cs
Source:
Marshal.cs

返回指定托管类的非托管形式的字段偏移量。

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

类型参数

T

托管值类型或格式化引用类型。 必须将该 StructLayoutAttribute 属性应用于该类。

参数

fieldName
String

类型中 T 字段的名称。

返回

IntPtr

nativeint

由平台调用声明的指定类中的参数的偏移量(以字节为单位 fieldName )。

注解

OffsetOf<T>(String) 提供非托管结构布局的偏移量,这不一定与托管结构布局的偏移量相对应。 封送结构可以转换布局并更改偏移量。 T泛型类型参数可以是值类型或格式化引用类型(具有顺序或显式布局)。 可以使用该方法获取整个布局 SizeOf<T>(T) 的大小。

注释

OffsetOf 可能会公开专用字段。

另请参阅

适用于