Constructor
Constructor is a special method which invoked automatically when we create a new instance. It is used to automatically initiate the values of fields present inside class. Constructor must always present inside a class and constructor name should be same as that of class name. There are 2 types of constructor when it comes to C# programming language, let us see both with its definition below
CODE
EG 1 . Creating Rectangle class with constructor.
class Program {
    static void Main() {
        //Invoking constructor with 4 arguments
        Rectangle wall = new Rectangle(5, 6, 7, 2.8);
        wall.RectangleCalculation();
    }
}
class Rectangle {
    public double length, width, height, density;
    //Constructor
    public Rectangle(double l,double w,double h,double d) {
        length = l;
        width = w;
        height = h;
        density = d;
    }
    public double Area() {
        return length * width;
    }
    public double Perimeter() {
        return 2 * (length+width);
    }
    public double Volume() {
        return Area() * height;
    }
    public double Weight() {
        return Volume() * density;
    }
    public void RectangleCalculation() {
        Console.WriteLine(Area());
        Console.WriteLine(Perimeter());
        Console.WriteLine(Volume());
        Console.WriteLine(Weight());
    }
}
(Click Here, For more exercises)