Export (0) Print
Expand All
Expand Minimize

OpCodes.Ret Field

Returns from the current method, pushing a return value (if present) from the callee's evaluation stack onto the caller's evaluation stack.

Namespace: System.Reflection.Emit
Assembly: mscorlib (in mscorlib.dll)

public static readonly OpCode Ret
public static final OpCode Ret
public static final var Ret : OpCode
Not applicable.

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

2A

ret

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. 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.

The ret instruction cannot be used to transfer control out of a try, filter, catch, or finally block. From within a try or catch, use the Leave instruction with a destination of a ret instruction that is outside all enclosing exception blocks. Because 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.

The following Emit method overload can use the ret opcode:

  • ILGenerator.Emit(OpCode)

Windows 98, Windows Server 2000 SP4, Windows Millennium Edition, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

The Microsoft .NET Framework 3.0 is supported on Windows Vista, Microsoft Windows XP SP2, and Windows Server 2003 SP1.

.NET Framework

Supported in: 3.0, 2.0, 1.1, 1.0

Community Additions

ADD
Show:
© 2014 Microsoft