OpCodes.Stloc 字段

定义

从计算堆栈的顶部弹出当前值并将其存储到指定索引处的局部变量列表中。Pops the current value from the top of the evaluation stack and stores it in a the local variable list at a specified index.

public: static initonly System::Reflection::Emit::OpCode Stloc;
public static readonly System.Reflection.Emit.OpCode Stloc;
 staticval mutable Stloc : System.Reflection.Emit.OpCode
Public Shared ReadOnly Stloc 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 0E < unsigned int16 @ NO__T-1FE 0E < unsigned int16 > stloc indexstloc index 从堆栈中弹出一个值并将其存储在本地变量 indexPops a value from the stack and stores it in local variable index.

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

  1. 将从堆栈中弹出一个值并将其放入本地变量 indexA value is popped off of the stack and placed in local variable index.

@No__t-0 指令从计算堆栈中弹出顶部值,并将其移到局部变量号 index 中,其中局部变量从0开始编号。The stloc instruction pops the top value off the evaluation stack and moves it into local variable number index, where local variables are numbered 0 onwards. 值的类型必须与当前方法本地签名中指定的局部变量的类型匹配。The type of the value must match the type of the local variable as specified in the current method's local signature.

如果存储在保持小于4个字节的整数值的局部变量中,长时间将在从堆栈移到局部变量时截断值。Storing into locals that hold an integer value smaller than 4 bytes long truncates the value as it moves from the stack to the local variable. 浮点值从其本机大小(类型 F)舍入到与参数相关联的大小。Floating-point values are rounded from their native size (type F) to the size associated with the argument.

更正 Microsoft 中间语言(MSIL)指令要求 index 是有效的本地索引。Correct Microsoft Intermediate Language (MSIL) instructions require that index be a valid local index. 对于 stloc 指令,index 必须在0到65534的范围内(具体而言,65535是无效的)。For the stloc instruction, index must lie in the range 0 to 65534 inclusive (specifically, 65535 is not valid). 排除65535的原因是实际的:可能的实现将使用2字节整数跟踪本地的索引,以及给定方法的局部变量总数。The reason for excluding 65535 is pragmatic: likely implementations will use a 2-byte integer to track both a local's index, as well as 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.

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

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

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

适用于