This won't compile
public struct Matrix
{
readonly double[] elems;
public Matrix(int rows, int cols)
{
this.elems=new double[rows*cols];
this.Rows=rows;
this.Columns=cols;
}
public int Rows { get; private set; }
public int Columns { get; private set; }
}
but this does:
public struct Matrix
{
readonly double[] elems;
public Matrix(int rows, int cols) : this()
{
this.elems=new double[rows*cols];
this.Rows=rows;
this.Columns=cols;
}
public int Rows { get; private set; }
public int Columns { get; private set; }
}
Why is that?
The compile time error is
error CS0188: The 'this' object cannot be used before all of its fields are assigned to
and
error CS0843: Backing field for automatically implemented property 'SO_MMul.Matrix.Columns' must be fully assigned before control is returned to the caller. Consider calling the default constructor from a constructor initializer.
Doesn't the parameterized constructor call the default constructor anyway?