This is a constructor-initializer which invokes another instance constructor immediately before the constructor-body. There are two forms of constructor initializers: this
and base
.
base
constructor initializer causes an instance constructor from the direct base class to be invoked.
this
constructor initializer causes an instance constructor from the class itself to be invoked. When constructor initializer does not have parameters, then parameterless constructor is invoked.
class Complex
{
public Complex() // this constructor will be invoked
{
}
public Complex(double real, double imaginary) : this()
{
Real = real;
Imaginary = imaginary;
}
}
BTW usually constructors chaining is done from constructors with less parameters count to constructors with more parameters (via providing default values):
class Complex
{
public Complex() : this(0, 0)
{
}
public Complex(double real, double imaginary)
{
Real = real;
Imaginary = imaginary;
}
}