我收到此错误:错误1:无法将类型'double [] []'隐式转换为'double []' [英] I got this error: Error 1: Cannot implicitly convert type 'double[][]' to 'double[]'
问题描述
我收到了以下代码:
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;
我得到这2个错误:
And I get this 2 errors:
Error 1: Cannot implicitly convert type ''double[][]'' to ''double[]''
简称"return ou"
referred to "return ou"
Error 2: Invalid rank specifier: expected '','' or '']''
指的是"double [] [] ou = new double [h] [w];"
我解决了错误1,我的函数是double [] [] myFunction(...)
referred to "double[][] ou = new double[h][w];"
I solved Error 1, my function was double[][] myFunction(...)
推荐答案
已通读 ^ ].
只是提示,您的代码中有一个锯齿状的数组,它是数组的数组,但我认为您追求的是多维数组.
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.
很可能,您想要的是要做的是这样:
Most likely, what you want to do is this:
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:
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];
这样,double
的每个内部数组可以具有不同的长度,因此是锯齿状数组".
现在,您可以了解Rod的建议,但是...为什么不简单地阅读C#手册(例如,从Microsoft帮助中获得)?
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)?
这篇关于我收到此错误:错误1:无法将类型'double [] []'隐式转换为'double []'的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!