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 [C#] public static readonly OpCode Initobj; [C++] public: static OpCode Initobj; [JScript] 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:
|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 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