我收到此错误:错误1:无法将类型'double [] []'隐式转换为'double []' [英] I got this error: Error 1: Cannot implicitly convert type 'double[][]' to 'double[]'

查看:75
本文介绍了我收到此错误:错误1:无法将类型'double [] []'隐式转换为'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屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆