public override string ToString() {
string matrixView = "";
for (int r=0; r<=this.rows; r++) {
for (int c=0; c<=this.columns; c++) {
}
}
return matrixView;
}
Note:
##################################
this.rows
= row number
this.columns
= column number
this.matrix
= 2-dimensional array used as data store
##################################
In this code, I aim to make seem for example 4x4 matrix like:
[0 0 0 0]
[0 0 0 0]
[0 0 0 0]
[0 0 0 0]
Each newline must be started with "[". Values(this.columns
times) and spaces(this.columns
-1 times) must be printed. Finally, the line must be ended with "]\n"
And these operations above must be done this.rows
times.
I think in this way. But nested loops always make me confuse. So, I tried several times but I couldn't be successful at it. And String.Concat
threw NullReferenceException
when I tried to concaten matrixView
with "[", "]\n" and this.matrix[r, c].ToString()
.