OpCodes.Ldelem 字段


按照指令中指定的类型,将指定数组索引中的元素加载到计算堆栈的顶部。Loads the element at a specified array index onto the top of the evaluation stack as the type specified in the instruction.

public: static initonly System::Reflection::Emit::OpCode Ldelem;
public static readonly System.Reflection.Emit.OpCode Ldelem;
 staticval mutable Ldelem : System.Reflection.Emit.OpCode
Public Shared ReadOnly Ldelem 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
A3 < T >A3 < T > ldelem typeTokldelem typeTok index 中的元素加载到堆栈顶部作为 typeTok类型。Loads the element at index onto the top of the stack as type typeTok.

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

  1. 对象引用 array 被推送到堆栈上。An object reference array is pushed onto the stack.

  2. index 的索引值推送到堆栈上。An index value index is pushed onto the stack.

  3. 从堆栈中弹出 indexarray;查找 arrayindex 位置上存储的值。index and array are popped from the stack; the value stored at position index in array is looked up.

  4. 值推送到堆栈上。The value is pushed onto the stack.

ldelem 指令在从零开始的一维 array 数组中加载具有索引 index (类型 native int)的元素的值,并将其放在堆栈顶部。The ldelem instruction loads the value of the element with index index (type native int) in the zero-based one-dimensional array array and places it on the top of the stack. 数组是对象,因此由 O类型的值表示。Arrays are objects, and hence represented by a value of type O.

返回值的类型由指令中的 typeTok 标记指定。The type of the return value is specified by the token typeTok in the instruction.

如果 array 为空引用,则会引发 NullReferenceExceptionNullReferenceException is thrown if array is a null reference.

如果 index 为负数或大于 array的上限,则会引发 IndexOutOfRangeExceptionIndexOutOfRangeException is thrown if index is negative, or larger than the upper bound of array.

以下 Emit 方法重载可以使用 ldelem 操作码:The following Emit method overload can use the ldelem opcode: