OpCodes.Initobj 字段

定义

将位于指定地址的值类型的每个字段初始化为空引用或适当的基元类型的 0。Initializes each field of the value type at a specified address to a null reference or a 0 of the appropriate primitive type.

public: static initonly System::Reflection::Emit::OpCode Initobj;
public static readonly System.Reflection.Emit.OpCode Initobj;
 staticval mutable Initobj : System.Reflection.Emit.OpCode
Public Shared ReadOnly Initobj As OpCode 

字段值

注解

下表列出了指令的十六进制和 Microsoft 中间语言(MSIL)程序集格式以及简短的参考摘要: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
FE 15 < T @ NO__T-1FE 15 < T > initobj typeTokinitobj typeTok 初始化值类型。Initializes a value type.

堆栈转换行为顺序如下:The stack transitional behavior, in sequential order, is:

  1. 要初始化的值类型的地址被推送到堆栈上。The address of the value type to initialize is pushed onto the stack.

  2. 从堆栈中弹出该地址;指定地址处的值类型初始化为类型 typeTokThe address is popped from the stack; the value type at the specified address is initialized as type typeTok.

@No__t-0 指令将按下推送地址指定的值类型的每个字段(类型为 native int&*)初始化为空引用或适当的基元类型的0。The initobj instruction initializes each field of the value type specified by the pushed address (of type native int, &, or *) to a null reference or a 0 of the appropriate primitive type. 调用此方法后,该实例已准备好调用构造函数方法。After this method is called, the instance is ready for a constructor method to be called. 如果 @no__t 为引用类型,则此指令的作用与 ldnull 后跟 stind.ref 相同。If typeTok is a reference type, this instruction has the same effect as ldnull followed by stind.ref.

Newobj 不同,initobj 不调用构造函数方法。Unlike Newobj, initobj does not call the constructor method. @no__t 用于初始化值类型,而 newobj 用于分配和初始化对象。Initobj is intended for initializing value types, while newobj is used to allocate and initialize objects.

以下 @no__t 0 方法重载可以使用 @no__t 操作码:The following Emit method overload can use the initobj opcode:

  • ILGenerator (OpCode,Type)ILGenerator.Emit(OpCode, Type)

适用于