C#
im very confused with constructors.. when will i say to myself that i need to create a constructor? kindly explain in the simplest way because i have read a lot of tutorials in the net but still i can't understand! ty n advnce
Loading
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
Ravinder ReddyPosted Dec 11, 2006, 1:10 PM
U need not to write a constructor until unless u want to send parameters to it. By default u will be having a default constructor which will take no arguments.
The purpose of the constructor is to create an object of a class. Constructors have the name same as the class name.
Ex
public class Student
{
//constructor
public Student()
{
}
}
U can write the initial process in the constructor that should be executed when ever the object was created.
U can write ur own constructors to a class with different which will take different arguments (constructor overloading)