What happened after Employee e = new Employee(“ConstructorParam1”);

Employee e = new Employee(“ConstructorParam1”);

  1. 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.
  1. 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
  1. It initializes the object’s type object pointer and sync block index members.
  1. 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.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s