OpCodes.Ldind_Ref 字段

定义

将对象引用作为 O(对象引用)类型间接加载到计算堆栈上。Loads an object reference as a type O (object reference) onto the evaluation stack indirectly.

public: static initonly System::Reflection::Emit::OpCode Ldind_Ref;
public static readonly System.Reflection.Emit.OpCode Ldind_Ref;
 staticval mutable Ldind_Ref : System.Reflection.Emit.OpCode
Public Shared ReadOnly Ldind_Ref As OpCode 

字段值

注解

下表列出了指令的十六进制和 Microsoft 中间语言(MSIL)程序集格式以及简短的参考摘要:The following table lists the instruction's hexadecimal and Microsoft Intermediate Language (MSIL) assembly format, along with a brief reference summary:

格式Format 程序集格式Assembly Format 说明Description
5050 ldind.refldind.ref 将地址 addr 处的对象引用作为 @no__t 类型加载到堆栈上Loads the object reference at address addr onto the stack as a type O

堆栈转换行为顺序如下:The stack transitional behavior, in sequential order, is:

  1. 地址被推送到堆栈上。An address is pushed onto the stack.

  2. 从堆栈中弹出该地址;提取位于地址处的对象引用。The address is popped from the stack; the object reference located at the address is fetched.

  3. 提取的引用将被推送到堆栈上。The fetched reference is pushed onto the stack.

@No__t 0 指令将对象引用(类型 @no__t 为-1、& 或 *)的指定地址作为 O 类型直接加载到堆栈上。The ldind.ref instruction indirectly loads the object reference the specified address (of type native int, &, or *) onto the stack as type O.

所有 ldind 指令都是指定相应内置值类的 @no__t 1 指令的快捷方式。All of the ldind instructions are shortcuts for a Ldobj instruction that specifies the corresponding built-in value class.

请注意,在将小于4个字节的整数值加载到计算堆栈上时,将其扩展到 int32 (而不是 native int)。Note that integer values of less than 4 bytes are extended to int32 (not native int) when they are loaded onto the evaluation stack. 将浮点值加载到计算堆栈上时,会将其转换为 @no__t 类型。Floating-point values are converted to F type when loaded onto the evaluation stack.

格式正确的 Microsoft 中间语言(MSIL)确保以与指针类型一致的方式使用 @no__t 的指令。Correctly-formed Microsoft Intermediate Language (MSIL) ensures that the ldind instructions are used in a manner consistent with the type of the pointer.

最初推送到堆栈上的地址必须与计算机上对象的自然大小对齐,否则可能出现 NullReferenceException (请参阅针对预防措施的 @no__t 1 前缀指令)。The address initially pushed onto the stack must be aligned to the natural size of objects on the machine or a NullReferenceException can occur (see the Unaligned prefix instruction for preventative measures). 返回地址的所有 MSIL 指令(例如 LdlocaLdarga)的结果将安全对齐。The results of all MSIL instructions that return addresses (for example, Ldloca and Ldarga) are safely aligned. 对于大于1个字节的数据类型,字节排序依赖于目标 CPU。For datatypes larger than 1 byte, the byte ordering is dependent on the target CPU. 依赖于字节排序的代码可能无法在所有平台上运行。Code that depends on byte ordering might not run on all platforms.

如果检测到无效地址,则可能引发 NullReferenceExceptionNullReferenceException can be thrown if an invalid address is detected.

以下 @no__t 0 方法重载可以使用 @no__t 操作码:The following Emit method overload can use the ldind.ref opcode:

  • ILGenerator.Emit(OpCode)ILGenerator.Emit(OpCode)

适用于