Skip to content

When to use constructors

maffle

Asked Dec 10, 2006, 6:34 PM EST1 answer
Share
LinkedInX
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

1 Answer

Know the answer? Post it. Somebody with the same question will find it here.

  • 0

    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)

    0