OpCodes.Ldstr Field

Microsoft Silverlight will reach end of support after October 2021. Learn more.

Pushes a new object reference to a string literal stored in the metadata.

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

Syntax

'Declaration
Public Shared ReadOnly Ldstr As OpCode
public static readonly OpCode Ldstr

Remarks

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

72 < T >

ldstr mdToken

Pushes a string object for the metadata string token mdToken.

The stack transitional behavior, in sequential order, is:

  1. An object reference to a string is pushed onto the stack.

The ldstr instruction pushes an object reference (type O) to a new string object representing the specific string literal stored in the metadata. The ldstr instruction allocates the requisite amount of memory and performs any format conversion required to convert the string literal from the form used in the file to the string format required at runtime.

The Common Language Infrastructure (CLI) guarantees that the result of two ldstr instructions referring to two metadata tokens that have the same sequence of characters return precisely the same string object (a process known as "string interning").

The following Emit method overload can use the ldstr opcode:

  • ILGenerator.Emit(OpCode, string)

Version Information

Silverlight

Supported in: 5, 4, 3

Silverlight for Windows Phone

Supported in: Windows Phone OS 7.1

Platforms

For a list of the operating systems and browsers that are supported by Silverlight, see Supported Operating Systems and Browsers.