Posts

Showing posts with the label C# Constructor

C# Constructor

Image
Constructor is a special method of the class that is automatically invoked when an instance of the class is created is called a constructor. the main use of the constructor is to initialize private fields of the class when you have not created a constructor in the class the compiler will automatically create a default constructor of the class. - The default constructor initializes all numeric fields in the class to zero and all string and objects fields to null. - A class can have any no. of constructors. - A constructor doesn't have any return type not even void. - A static constructor can't be parametrized. - Within a class you can create only one static constructor. Types of constructors - 1. Default Constructor - A constructor without any parameters is called default constructor. - The drawback of the default constructor is that every instance of the class will be initialized to the same values, and it is not possible to initialize each instance of the class with different...