Constructor in C sharp

Some Points about Constructor


  • It is a special method present under a class responsible for initializing the variable of class.
  • The name of a  constructor method will exactly be the same name of the class in which it is present and moreover it is  a non-value returning method.
  • Without a constructor under a class we can never create instance Of the class.
  • A constructor is mandatory for creating instance of the class, it is the responsibility of the programmer to explicitly define a constructor in a class. Whereas  if the programmer doesn’t define the constructor explicitly under the class on behalf of the programmer compiler define constructor in that class and we call the constructor as implicit constructor.
  • If constructor are Implicitly define under a class they will be public constructor.
We can also define constructor explicitly under a class as following:-

                          [<modifier>]  [<name>]   [<parameter definition>]
                         {
 
                          }


Constructor of a class even if it is implicitly  define or explicitly  define it is  must to call the constructor explicitly  at the time of creating the instance.

No comments:

Post a Comment