Employee e = new Employee(“ConstructorParam1”);
- It calculates the number of bytes required by all instance fields defined in the type and all of its base types up to and including system.object (which defines no instance fields of its own). Every object on the heap requires some additional members – called the type object pointer and the sync block index – used byte the CLR to manage the object. The bytes for these additional members are added to the size of the object.
- It allocates memory for the object by allocating the number of bytes required for the specified type from the managed heap; all of these bytes are then set to zero
- It initializes the object’s type object pointer and sync block index members.
- The type’s instance constructor is called, passing it any arguments (the string “ConstructorParam1” in the preceding example) specified in the call to new. Most compiler automatically emit code in a constructor to call a base class’s constructor. Each constructor is responsible for initializing the instance fields defined by the type whose constructor is being called. Eventually, System.Object’s constructor is called, and this constructor method does nothing but return .
After new has performed all of the these operations, it returns a reference (or pointer) to the newly created object. In the preceding code example, this reference is saved in the variable e, which is of type Employee.