Why is the "new" keyword used for instantiating an object in .Net ?

 Posted by Akiii on 5/15/2011 | Category: C# Interview questions | Views: 8795 | Points: 40

The "new" keyword instructs the compiler to instantiate a new object, with appropriate number of bytes depending upon the type of the object and gather required memory from the heap.


Classname objectname = new  Classname();

Thanks and Regards

Source: http://www.dotnetuncle.com/csh | Asked In: Many Interviews | Alert Moderator 

Comments or Responses

Posted by: Puneet20884 on: 5/15/2011 | Points: 10
a simple answer to it is:
The objects to the classes are reference type in nature so you need to assign them a memory to the heap by calling their default constructor with new keyword.
Posted by: Vinaym on: 5/17/2011 | Points: 10
good one

Posted by: Shoeb2222 on: 6/22/2011 | Points: 10
It is used for allocating memory to the object.

Login to post response