Interviews16 answers
What is the Signification of the "new " keyword in C#? example
16 Answers
"new" keyword is used to create a object in a heap. Basically any object have two parts first is "reference variable" and other is "object" itself , reference variable is resides in stack and object is in heap. So new in used to create the object in heap and the reference variable is used to point the object in heap.
Ex : Employee E1(ref var)= new Employee();(object created in heap)
and these objects are clean by the garbage collector when it not used for long times.
Alok TripathiPosted Mar 28, 2017, 11:47 PM EDT
New is used to allocate the memory for object reference
Ashu ElahiPosted Sep 5, 2016, 10:00 PM EDT
To allocate reference to instance
Thanks
Amatya AgyeyPosted Apr 6, 2016, 8:24 PM EDT
used for class object creation and method hiding
vipin kvPosted Oct 5, 2015, 1:40 AM EDT
new keyword can be used to create class instance or can be used in method hiding
vipin kvPosted Oct 5, 2015, 1:40 AM EDT
new keyword is use to get an reference of a class, structure .
when we use a new operator then a memory block of size of object type(class/reference)
is allocated in memory and address of this memory block is assigned to object
Rahul PrajapatPosted Jun 1, 2015, 6:02 PM EDT
new is used to allocate memory in hard drive.
example: int() a = new int(10)
here, new keyword is allocating 10 integer numbers in a array
Safayat ZisanPosted Apr 17, 2015, 1:16 PM EDT
new keyword is use to get an reference of a class, structure .
when we use a new operator then a memory block of size of object type(class/reference)
is allocated in memory and address of this memory block is assigned to object
Pankaj Kumar ChoudharyPosted Mar 28, 2015, 5:29 PM EDT
New is a keyword. To get reference or addressing of the objects.
New keyword will work for Variables(int,float ,..... example : int i=new int();)
New keyword will work for class ( classA a =new classA(); )
New keyword also work as modifier
publc classA
{
public void AB(){ }
}
public classB:A
{
new public void AB() { }
}
More over it will use to assign memory dynamically
Maruthi PallamalliPosted Feb 10, 2015, 11:58 PM EST
It is allocating reference to instance
Dhanik SahniPosted Oct 9, 2014, 5:43 AM EDT
http://msdn.microsoft.com/en-us/library/ms173153.aspx
Munesh SharmaPosted Oct 9, 2014, 1:12 AM EDT
Example-
foo obj = new foo();
Left Part initializes/declares the object and right part ( new foo() ) allocates memory to newly created Object.
Please Correct me if i am wrong. :)
Manoj RawatPosted Aug 9, 2014, 4:43 AM EDT
In C#, a method in a derived class can have the same name as a method in the base class. You can specify how the methods interact by using the new and override keywords. The override modifier extends the base class method, and the new modifier hides it. The difference is illustrated in the examples in this topic.
jayasriPosted Aug 1, 2014, 5:07 AM EDT
used for creating the new object for the class and hiding the member of parent class in child if it is intended.For similar kind of interview question check this also
c# interview questions
Mohit KumarPosted Jul 27, 2014, 10:26 PM EDT
used to create instance of a class or to shadow a method declared in base class.
Sandesh PatilPosted Jul 24, 2014, 4:06 AM EDT
In C# the "new" keyword is used to create an instance of a class.
for example:
public class Student
{
}
Student objstudent=new Student():
Krishna Rajput SinghPosted Jul 17, 2014, 1:38 AM EDT









