Wednesday, October 1, 2014

What is Constructor in C# ?


In C#, Constructor is a special kind of a method. It is automatically called, when the object is created. Constructors do not return values and have the same name as the class.  
Constructors are responsible for object initialization and memory allocation of its class. There is always at least one constructor in every class. If you don't write a constructor in class, 
C# compiler will automatically provide one constructor for that class, called default (parameter less) constructor.

Types of Constructor

Generally, constructors are of three types. But C# doesn't support copy constructor.

  1. Default Constructor(Non-Parameterized constructor)
  2. Parameterized Constructor
  3. Copy Constructor
  4.  Static Constructor
  5.  Private Constructor

Default Constructor Example
Example:

No comments:

Post a Comment

Object Oriented Programming (oop)

The programming in which data is logically represented in the form of a class and physically represented in the form an object is called a...