Finds the value of a field in the object whose reference is currently on the evaluation stack.
[Visual Basic] Public Shared ReadOnly Ldfld As OpCode [C#] public static readonly OpCode Ldfld; [C++] public: static OpCode Ldfld; [JScript] public static var Ldfld : OpCode;
The following table lists the instruction's hexadecimal and Microsoft Intermediate Language (MSIL) assembly format, along with a brief reference summary:
|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:
- An object reference (or pointer) is pushed onto the stack.
- The object reference (or pointer) is popped from the stack; the value of the specified field in the object is found.
- 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 natural 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.
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 constructor overload can use the ldfld opcode:
- ILGenerator.Emit(OpCode, FieldInfo)
Platforms: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 family