Constructor, is a special method. It is used primarily to initialize an object when it is created, to assign an initial value to an object member variable, and to always use the new operator in the statement that creates the object. A particular class can have more than one constructor, which is an overload of the constructor, depending on the number of arguments or different types of arguments.
Publicclass taxi{public bool Isinitialized;public Taxi () {isinitialized = true;}} Class testtaxi{static void Main () {Taxi t = new Taxi (); System.Console.WriteLine (t.isinitialized);} The output is true; The constructor has the following characteristics: The 1 class name is the same as the method name 2. No return value Call object is automatically called constructor: Class Name Object name = Utility constructor () Taxi T =new Taxi (); Note: The initial state system sends a parameterless constructor for free, When we write a constructor that has a parameter, the system does not send us a parameterless construct, so we need to redefine a parameterless constructor ourselves.
C # Constructors