Initobj Field
Collapse the table of content
Expand the table of content

OpCodes.Initobj Field

Initializes all the fields of the object at a specific address to a null reference or a 0 of the appropriate primitive type.

[Visual Basic]
Public Shared ReadOnly Initobj As OpCode
public static readonly OpCode Initobj;
public: static OpCode Initobj;
public static var Initobj : 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
FE 15 < T > initobj classTok Initializes a value type.

The stack transitional behavior, in sequential order, is:

  1. The address of an object to initialize is pushed onto the stack.
  2. The address is popped from the stack; the value type object at the specified address is initialized as type classTok.

The initobj instruction initializes all the fields of the object specified by the pushed address (of type natural int, &, or *) to a null reference or a 0 of the appropriate primitive type. After this method is called, the instance is ready for the constructor method to be called. Behavior is unspecified if either the address is not a pointer to an instance of the class represented by classTok, or if classTok does not represent a value type.

Unlike Newobj, the constructor method is not called by initobj. Initobj is intended for initializing value types, while newobj is used to allocate and initialize objects.

The following Emit constructor overloadscan use the initobj opcode:

  • ILGenerator.Emit(OpCode, Type)


Platforms: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 family

See Also

OpCodes Class | OpCodes Members | System.Reflection.Emit Namespace

© 2016 Microsoft