Click here to Skip to main content
15,942,847 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I have this function made with jagged array, but I need it to be in 2D array so I can use it in my application.

public static double[][] InvertMatrix(double[][] A)
    int n = A.Length;
    //e will represent each column in the identity matrix
    double[] e;
    //x will hold the inverse matrix to be returned
    double[][] x = new double[n][];
    for (int i = 0; i < n; i++)
        x[i] = new double[A[i].Length];

I just need to convert
x[i] = new double[A[i].Length];

to a 2D array. How can I do that?
Sergey Alexandrovich Kryukov 10-Oct-14 0:13am    
Do you mean to have a double[,] array? Is it supposed to be n*n? But what's the problem?
Wael Tayara 10-Oct-14 0:16am    
I'm trying to convert the whole function from Jagged array into 2D array..
Sergey Alexandrovich Kryukov 10-Oct-14 0:32am    
All right, but you did not answer any of my questions. What have you tried so far?
Wael Tayara 10-Oct-14 0:35am    
I converted everything except for the line I have posted, I don't this that I would need to initialize a new array on each iteration ... ?!
Sergey Alexandrovich Kryukov 10-Oct-14 1:30am    
It all makes no sense. Your declaration is x[][]. It cannot be indexed as x[i]. There is no "convert". You need to create and object of the type double[,] (what else could be considered as "2D array"? only double[][] or double [,]), and populate one array using the data from another one.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900