Expand Minimize
This topic has not yet been rated - Rate this topic

OpCodes.Ldfld Field

Finds the value of a field in the object whose reference is currently on the evaluation stack.

Namespace:  System.Reflection.Emit
Assembly:  mscorlib (in mscorlib.dll)
'Declaration
Public Shared ReadOnly Ldfld As OpCode

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

7B < T >

ldfld field

Pushes the value of a field in a specified object onto the stack.

The stack transitional behavior, in sequential order, is:

  1. An object reference (or pointer) is pushed onto the stack.

  2. The object reference (or pointer) is popped from the stack; the value of the specified field in the object is found.

  3. The value stored in the field is pushed onto the stack.

The ldfld instruction pushes the value of a field located in an object onto the stack. The object must be on the stack as an object reference (type O), a managed pointer (type &), an unmanaged pointer (type native int), a transient pointer (type *), or an instance of a value type. The use of an unmanaged pointer is not permitted in verifiable code. The object's field is specified by a metadata token that must refer to a field member. The return type is the same as the one associated with the field. The field may be either an instance field (in which case the object must not be a null reference) or a static field.

The ldfld instruction can be preceded by either or both of the Unaligned and Volatile prefixes.

NullReferenceException is thrown if the object is null and the field is not static.

MissingFieldException is thrown if the specified field is not found in the metadata. This is typically checked when Microsoft Intermediate Language (MSIL) instructions are converted to native code, not at run time.

The following Emit method overload can use the ldfld opcode:

  • ILGenerator.Emit(OpCode, FieldInfo)

.NET Framework

Supported in: 4.5.1, 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 8, Silverlight 8.1

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.

Did you find this helpful?
(1500 characters remaining)
Thank you for your feedback
Show:
© 2014 Microsoft. All rights reserved.