System.Reflection.Emit.OpCodes.Switch Field

Implements a jump table.

Syntax

public static readonly OpCode Switch

Remarks

The following table lists the instruction's hexadecimal and Microsoft Intermediate Language (MSIL) assembly format, along with a brief reference summary:

45 < unsigned int32 > < int32 >... < int32 >

switch (N, t1, t2... tN)

Jumps to one of N values.

The stack transitional behavior, in sequential order, is:

[The 'ordered' type of list has not been implemented in the ECMA stylesheet.]

The switch instruction implements a jump table. The format of the instruction is an unsigned int32 representing the number of targets N, followed by N int32 values specifying jump targets. These targets are represented as offsets (positive or negative) from the beginning of the instruction following this switch instruction.

The switch instruction pops a value off the stack and compares it, as an unsigned integer, to N. If value is less than N, execution is transferred to the target indexed by value, where targets are numbered from 0 (for example, a value of 0 takes the first target, a value of 1 takes the second target, and so on). If the value is greater than or equal to N, execution continues at the next instruction (fall through).

If the target instruction has one or more prefix codes, control can only be transferred to the first of these prefixes.

Control transfers into and out of try, catch, filter, and finally blocks cannot be performed by this instruction. (Such transfers are severely restricted and must use the leave instruction instead).

The following ILGenerator.Emit(OpCode) method overload can use the switch opcode. The Label[] argument is an array of Labels representing 32-bit offsets.

  • ILGenerator.Emit(OpCode, Label[])

Requirements

Namespace: System.Reflection.Emit
Assembly: mscorlib (in mscorlib.dll)
Assembly Versions: 1.0.5000.0, 2.0.0.0, 4.0.0.0