Export (0) Print
Expand All
Expand Minimize

OpCodes.Ldind_Ref Field

Loads an object reference as a type O (object reference) onto the evaluation stack indirectly.

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

public static readonly OpCode Ldind_Ref

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

50

ldind.ref

Loads the object reference at address addr onto the stack as a type O

The stack transitional behavior, in sequential order, is:

  1. An address is pushed onto the stack.

  2. The address is popped from the stack; the object reference located at the address is fetched.

  3. The fetched reference is pushed onto the stack.

The ldind.ref instruction indirectly loads the object reference the specified address (of type native int, &, or *) onto the stack as type O.

All of the ldind instructions are shortcuts for a Ldobj instruction that specifies the corresponding built-in value class.

Note that integer values of less than 4 bytes are extended to int32 (not native int) when they are loaded onto the evaluation stack. Floating-point values are converted to F type when loaded onto the evaluation stack.

Correctly-formed Microsoft Intermediate Language (MSIL) ensures that the ldind instructions are used in a manner consistent with the type of the pointer.

The address initially pushed onto the stack must be aligned to the natural size of objects on the machine or a NullReferenceException can occur (see the Unaligned prefix instruction for preventative measures). The results of all MSIL instructions that return addresses (for example, Ldloca and Ldarga) are safely aligned. For datatypes larger than 1 byte, the byte ordering is dependent on the target CPU. Code that depends on byte ordering might not run on all platforms.

NullReferenceException can be thrown if an invalid address is detected.

The following Emit method overload can use the ldind.ref opcode:

  • ILGenerator.Emit(OpCode)

.NET Framework

Supported in: 4.5, 4, 3.5, 3.0, 2.0, 1.1, 1.0

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

.NET for Windows Store apps

Supported in: Windows 8

.NET for Windows Phone apps

Supported in: Windows Phone 8.1, Windows Phone Silverlight 8.1, Windows Phone Silverlight 8

Windows Phone 8.1, Windows Phone 8, Windows 8.1, Windows Server 2012 R2, Windows 8, Windows Server 2012, Windows 7, Windows Vista SP2, Windows Server 2008 (Server Core Role not supported), Windows Server 2008 R2 (Server Core Role supported with SP1 or later; Itanium not supported)

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

Show:
© 2014 Microsoft