0

I can't get list result with all the elements but only with the last one (tempmatrix).

The behaviour is for the overwrite and not for the append.

I'm wrong but I can't see where. Please can you help me?

result should be a List of matrices

public static List<int[,]> SplitSquareMatrix (int [,] mat, int raw) {

            List<int[,]> result = new List<int[,]>();
            int[,] tempmatrix = new int[raw, raw];
            int tempcont = 5;
            int a = 0;
            for (int i = 0; i < mat.GetLength(0); i++)
            {
                if (i == tempcont)
                {
                    result.Add(tempmatrix); 
                    a = 0; 
                    continue;
                }
                for (int j = 0; j < mat.GetLength(1); j++)
                {
                    tempmatrix[a, j] = mat[i,j];
                } 
                a++;
                if (i > tempcont) tempcont += 6; 

            }
            return result;
        }
Diego
  • 11
  • 6

0 Answers0