Constructors are a public methods with the same name as a class were they resides. Constructors are always created with a class, weather we write it ourselves or if class creates it for us(although it will not be visible ). Role of constructors is to initialize fields when we instantiate class. It is possible to create multiple constructors. Adding „: this()“ after parameters of constructor with parameters will execute default constructor before constructors with parameters. To easily create constructors type ctor keyword an new one will be generated for you.

 

If you have ever initialized class you have consumed constructors in one way or another. Example of consuming constructors would be in previous example where we have instantiated ClassWithConstructor class with string “Mike” and integer 1.

 

Is it possible to forbid class to initialize constructor?

Yes it is, just create empty one and set private access modifier.

 

What about other access modifiers? Can I use them all?

Public, private, protected, internal, or protected internal access modifiers are allowed to be used with constructors.

 

How can i initialize base class constructors ?

Simply type

after constructors parameters . Remember, you don’t have to supply parameters for base class constructor  because base constructor will always be called before derived class constructor, weather we call it or not.