OpCodes.Ret 字段

定义

从当前方法返回,并将返回值(如果存在)从被调用方的计算堆栈推送到调用方的计算堆栈上。Returns from the current method, pushing a return value (if present) from the callee's evaluation stack onto the caller's evaluation stack.

public: static initonly System::Reflection::Emit::OpCode Ret;
public static readonly System.Reflection.Emit.OpCode Ret;
 staticval mutable Ret : System.Reflection.Emit.OpCode
Public Shared ReadOnly Ret 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
2A2A retret 从方法返回,可能返回值。Returns from method, possibly returning a value.

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

  1. 从被调用方的计算堆栈中弹出返回值。The return value is popped from the callee evaluation stack.

  2. 在步骤1中获取的返回值被推送到调用方计算堆栈上。The return value obtained in step 1 is pushed onto the caller evaluation stack.

如果返回值不在被调用方的计算堆栈上,则不返回任何值(对于被调用方或调用方方法,不返回任何堆栈转换行为)。If the return value is not present on the callee evaluation stack, no value is returned (no stack transition behaviors for either the callee or caller method).

当前方法的返回值的类型(如果有)确定要从堆栈顶部获取的值的类型,并将其复制到调用当前方法的方法的堆栈上。The type of the return value, if any, of the current method determines the type of value to be fetched from the top of the stack and copied onto the stack of the method that called the current method. 当前方法的计算堆栈必须为空,但要返回的值除外。The evaluation stack for the current method must be empty except for the value to be returned.

@No__t-0 指令不能用于将控制转移出 @ no__t-1、filtercatchfinally 块。The ret instruction cannot be used to transfer control out of atry, filter, catch, or finally block. 在 @no__t 0 或 catch 中,将 Leave 指令与不在所有封闭异常块之外的 @no__t 3 指令的目标一起使用。From within a try or catch, use the Leave instruction with a destination of a ret instruction that is outside all enclosing exception blocks. 由于 @no__t 0 和 @no__t 1 块在逻辑上是异常处理的一部分,而不是其代码的嵌入方法,因此,正确生成的 Microsoft 中间语言(MSIL)指令不会执行从 filterfinallyBecause the filter and finally blocks are logically part of exception handling and not the method in which their code is embedded, correctly generated Microsoft Intermediate Language (MSIL) instructions do not perform a method return from within a filter or finally.

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

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

适用于