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.

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

public static readonly OpCode Initobj
public static final OpCode Initobj
public static final var Initobj : OpCode

The following table lists the instruction's hexadecimal and Microsoft Intermediate Language (MSIL) assembly format, along with a brief reference summary:


Assembly Format


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 method overload can use the initobj opcode:

  • ILGenerator.Emit(OpCode, Type)

Windows 98, Windows 2000 SP4, Windows Millennium Edition, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see System Requirements.

.NET Framework

Supported in: 2.0, 1.1, 1.0

Community Additions

© 2016 Microsoft