What is Constructor in C#?

⦁    Special method of class. 

⦁    It is used to initialize objects.

⦁    It is called automatically when the object of the class is created.

⦁    It’s also like a method which contains different instructions that are executed at the object creation time.

⦁    It is used to assign initial values to the data members of the same class.

⦁    Constructor name should be the same as class name.

⦁    Constructor does not return any value.

⦁    All classes have constructors by default.

⦁    Constructors are parameterized also.

⦁    It can be overload.

⦁    Constructors are time savers.

⦁    A class has only one static constructor.

Types of Constructor in C#

1.    Default Constructor

2.    Parameterized Constructor

Default Constructor

⦁    Default Constructors are non-parameterized constructors.

⦁    In a class, a default constructor initializes “Zero” to all the numeric data members and “Null” to all non-numeric data members.

Parameterized Constructor

⦁    A constructor that has at least one parameter is called a Parameterized Constructor.

⦁    It is used to provide different values for distinct objects.

Read Also: how to image upload in C#