Click here to Skip to main content
15,912,756 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I got this code:

double[][] ou = new double[h][w];

for(i=0;i<h;i++)
   for(int j=0;j<w;j++)
      ou[i][j] = sortie[z++];

return ou; 


And I get this 2 errors:
Error 1: Cannot implicitly convert type 'double[][]' to 'double[]'


referred to "return ou"

Error 2: Invalid rank specifier: expected ',' or ']'


referred to "double[][] ou = new double[h][w];"


EDIT:

I solved Error 1, my function was double[][] myFunction(...)
Posted
Updated 22-Jan-11 18:47pm
v2

Have a read through Arrays Tutorial (C#)[^] on MSDN.

Just as a hint, you have a jagged array in your code which is an array of arrays but I think what you are after is a multi-dimensional array.
 
Share this answer
 
v2
Comments
Sergey Alexandrovich Kryukov 23-Jan-11 22:50pm    
Good minimalistic manual - my 5 (and who cares it's 2003?)
Rod Kemp 23-Jan-11 22:59pm    
Thankfully the basics don't change, unfortunately it seems that some people don't know the basics.
Sergey Alexandrovich Kryukov 24-Jan-11 9:57am    
I would say don't want to know basics...
Thank you.
--SA
Most likely, what you want to do is this:

C#
int h = 3; int w = 4; 
double[,] ou = new double[h, w];

Do you see the difference?

What you tried to write could make sense if you do this:

C#
double[][] ou = new double[h][];

//now you have an array of h arrays of <code>double</code>,
//but each array of <code>double</code> is <code>null</code>;
//you can initialize each array of <code>double</code> separately (in loop for example);
//but let's look at couple of several elements:
ou[0] = new double[w];
uo[1] = new double [200];
uo[1] = new double [w * 2];


This way, each inner array of double can have different length, hence "jagged array".

Now, you can learn what Rod suggested but... why not simply reading C# manual (for example, from Microsoft help)?
 
Share this answer
 

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