OpCodes.Ldloc 字段

定义

将指定索引处的局部变量加载到计算堆栈上。Loads the local variable at a specific index onto the evaluation stack.

public: static initonly System::Reflection::Emit::OpCode Ldloc;
public static readonly System.Reflection.Emit.OpCode Ldloc;
 staticval mutable Ldloc : System.Reflection.Emit.OpCode
Public Shared ReadOnly Ldloc 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
FE 0C < unsigned int16 >FE 0C < unsigned int16 > ldloc indexldloc index 将索引 index 处的局部变量加载到堆栈上。Loads the local variable at index index onto stack.

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

  1. 将指定索引处的本地变量值推送到堆栈上。The local variable value at the specified index is pushed onto the stack.

@No__t-0 指令将传递的索引处的局部变量数字的内容推送到计算堆栈上,其中本地变量从0开始编号。The ldloc instruction pushes the contents of the local variable number at the passed index onto the evaluation stack, where the local variables are numbered 0 onwards. 仅当方法的 initialize 标志为 true 时,才在输入方法之前,将局部变量初始化为0。Local variables are initialized to 0 before entering the method only if the initialize flag on the method is true. 可能存在65535(2 ^ 16-1)个本地变量(0-65534)。There are 65,535 (2^16-1) local variables possible (0-65,534). 索引65535无效,因为可能的实现将使用2字节整数跟踪本地的索引,以及给定方法的局部变量总数。Index 65,535 is not valid since likely implementations will use a 2-byte integer to track both a local's index, along with the total number of locals for a given method. 如果已将65535的索引设为有效,则需要更宽的整数来跟踪此类方法中的局部变量的数目。If an index of 65535 had been made valid, it would require a wider integer to track the number of locals in such a method.

@No__t-0、@no__t @no__t 和 @no__t 3 说明提供了一个有效的编码,用于访问前四个局部变量。The ldloc.0, ldloc.1, ldloc.2, and ldloc.3 instructions provide an efficient encoding for accessing the first four local variables.

值的类型与在方法头中指定的局部变量的类型相同。The type of the value is the same as the type of the local variable, which is specified in the method header. 请参阅 Partition I. 小于4个字节的局部变量在加载到堆栈上时,将扩展为类型 int32See Partition I. Local variables that are smaller than 4 bytes long are expanded to type int32 when they are loaded onto the stack. 浮点值扩展为其本机大小(类型 F)。Floating-point values are expanded to their native size (type F).

以下 Emit 方法重载可以使用 @no__t 操作码:The following Emit method overloads can use the ldloc opcode:

  • ILGenerator (OpCode,LocalBuilder)ILGenerator.Emit(OpCode, LocalBuilder)

  • ILGenerator (操作码,short)ILGenerator.Emit(OpCode, short)

适用于