OpCodes.Conv_I2 字段


将位于计算堆栈顶部的值转换为 int16,然后将其扩展(填充)为 int32Converts the value on top of the evaluation stack to int16, then extends (pads) it to int32.

public: static initonly System::Reflection::Emit::OpCode Conv_I2;
public static readonly System.Reflection.Emit.OpCode Conv_I2;
 staticval mutable Conv_I2 : System.Reflection.Emit.OpCode
Public Shared ReadOnly Conv_I2 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
6868 约定conv.i2 转换为 int16,将 @no__t 推送到堆栈上。Convert to int16, pushing int32 on stack.

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

  1. value 推送到堆栈上。value is pushed onto the stack.

  2. 从堆栈中弹出 value,并尝试执行转换操作。value is popped from the stack and the conversion operation is attempted.

  3. 如果转换成功,则将结果值推送到堆栈上。If the conversion is successful, the resulting value is pushed onto the stack.

@No__t 操作码将堆栈顶部的 value 转换为操作码中指定的类型,并将转换后的值保留在堆栈的顶部。The conv.i2 opcode converts the value on top of the stack to the type specified in the opcode, and leave that converted value on the top of the stack. 小于4个字节的整数值在加载到计算堆栈时将扩展到 int32 (除非使用 @no__t 或 conv.u,在这种情况下,结果也 native int)。Integer values of less than 4 bytes are extended to int32 when they are loaded onto the evaluation stack (unless conv.i or conv.u is used, in which case the result is also native int). 浮点值将转换为 @no__t 类型。Floating-point values are converted to the F type.

从浮点数到整数值的转换会将数字截断到零。Conversion from floating-point numbers to integer values truncates the number toward zero. float64 转换到 @no__t 时,精度可能会丢失。When converting from a float64 to a float32, precision can be lost. 如果 value 太大,无法容纳 float32 (F)、正无穷(如果 value 为正)或负无穷(如果 value 为负数)。If value is too large to fit in a float32 (F), positive infinity (if value is positive) or negative infinity (if value is negative) is returned. 如果在将一个整数类型转换为另一个整数类型时发生溢出,则会截断高序位。If overflow occurs converting one integer type to another, the high order bits are truncated. 如果结果小于 int32,则值将进行符号扩展以填充槽。If the result is smaller than an int32, the value is sign-extended to fill the slot.

如果发生溢出,将浮点类型转换为整数,则返回的值是未指定的。If overflow occurs converting a floating-point type to an integer the value returned is unspecified.

使用此字段时,不会引发异常。No exceptions are ever thrown when using this field. 请参阅 Conv_Ovf_I2Conv_Ovf_I2_Un,了解当结果类型无法正确表示结果值时将引发异常的等效说明。See Conv_Ovf_I2 and Conv_Ovf_I2_Un for equivalent instructions that will throw an exception when the result type can not properly represent the result value.

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

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