Question:
What are constructor in C#?
Answer:
Constructor is a method in the class which has the same name as the class (in VB.Net its New()). It initialises the member attributes whenever an instance of the class is created. Source: CoolInterview.com
Constructor is a member method of a class which is invorked when object is created to the class.A constructor name should be same of class name in c#.net.We have 2 types of constructors 1)Instence Constructor a)Static constrector 2) and non instrector. a)Default (b)copy (c)parameter(private) Source: CoolInterview.com
Answered by: madduri srinivas yadav | Date: 10/18/2009
| Contact madduri srinivas yadav
constuctor is a special member function whose name is same as the class name for example
public void test() { public test() { this is a constuctor. here u have write a logic of constructor } } Source: CoolInterview.com
Answered by: harsh shah | Date: 10/30/2009
| Contact harsh shah
Constructor is public method which is called automatically when object of class is created. It is created when you want to initilize class members of the class.Constructor of class is called single time in life cycle of the object.Constructor in static class can also be created and this is called "Private / Staic " constructor. We can not create object of static class because of that this constructor is called only single time when first time class name is used to use any member of same class. Every class has defult zero argument constuctor, but when we use constructor overloading then we have to write zero argument constrouctor too. Source: CoolInterview.com
Answered by: Harvinder | Date: 10/30/2009
| Contact Harvinder
Its is a member function in class which has the same name as the class name. There is no return type. It initializes the member variable as soon as the instance of the class in created. In the lifetime of a object only one constructor can be called. Source: CoolInterview.com
Answered by: kiranmayi | Date: 11/3/2009
| Contact kiranmayi
Constructor in C# are of two types: =>Instance Constructor:It will be called automatically when the object is created =>Static Constructor:It is not necessary to create a object.As soon as the compiler enters the Main() function the static constructor is called automatically. Source: CoolInterview.com
Answered by: Kalaivani.G | Date: 11/13/2009
| Contact Kalaivani.G
Constructor is a special type of method which have same name as of class name and has no return type even void.you can't directly invoke a constructor but it is automatically invoked when a object of a class is created. It is used to intialize class variables. Source: CoolInterview.com
Answered by: pragnyan kumar | Date: 5/19/2010
| Contact pragnyan kumar
If you have the better answer, then send it to us. We will display your answer after the approval.
Rules to Post Answers in CoolInterview.com:-
- There should not be any Spelling Mistakes.
- There should not be any Gramatical Errors.
- Answers must not contain any bad words.
- Answers should not be the repeat of same answer, already approved.
- Answer should be complete in itself.
|