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.
Example:- Default Constructor(Non-Parameterized constructor)
- Parameterized Constructor
- Copy Constructor
- Static Constructor
- Private Constructor
No comments:
Post a Comment