OpCodes.Initobj Field
Assembly: mscorlib (in mscorlib.dll)
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:
-
The address of an object to initialize is pushed onto the stack.
-
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.