I am trying to transpose a int[,] matrix. But I do not get the correct output. I have done the transposition with two for-loops but I think I did a mistake there. I just can't point it out.
Here is my code:
int[,] matrix = new int[2,2];
matrix[0, 0] = 1;
matrix[0, 1] = 2;
matrix[1, 0] = 3;
matrix[1, 1] = 4;
public void transponieren()
{
int[,] temp = this.matrix;
for (int i = 0; i < this.matrix.GetLength(0); i++)
{
for (int j = 0; j < this.matrix.GetLength(1); j++)
{
this.matrix[i, j] = temp[j, i];
}
}
transponiert = true;
}
With an input of
[ 1 , 2 ]
[ 3 , 4 ]
I get an output of
[ 1 , 3 ]
[ 3 , 4 ]
I have already another solution that works but I want to know what I did wrong here as I only copied the working solution from somewhere else.