双区别[*,*]翻番[] []在C# [英] difference between double[*,*] to double[][] in c#
问题描述
我用
double [,] marks=new double[26,5]
int[] function = object.verify(marks)
public void verifymarks(double[][] marks)
错误我得到的是不能转换的双[ 的]翻番[] []
I试图在网上搜索,但couldnot找到任何解决方案。我刚开始使用C#。请帮忙。 THankx提前
error i get is cannot convert from double[,] to double[][] i tried to search in the internet but couldnot find any solution. I have just began to use c#. Please Help. THankx in advance
推荐答案
双击[] []
参差不齐。这是字面上的数组的数组。
double[][]
is jagged. It's literally an array of arrays.
双击[,]
是多维的。它得到特殊的编译器处理。
double[,]
is multidimensional. It gets special compiler treatment.
他们有不同的内存布局。 双击[] []
是保存到另一个数组的引用,而阵列双[,]
是布局单维以方便使用。
They have different memory layouts. double[][]
is an array which holds references to the other arrays, while double[,]
is laid out single-dimensionally for easier use.
另一个区别是,他们还能持有什么数据。交错数组可以是这样的:
Another difference is what data they can hold. A jagged array can be like this:
1231243245345345345345
23423423423423
2342342343r234234234234234234
23423
在一个多维数组必须是一个完美的表,如下所示:
While a multidimensional array has to be a perfect table, like this:
34534534534534
34534534534533
34534534534534
34534534534545
一个办法来解决它是使用可空 INT
秒。
A way to get around it would be to use nullable int
s.
现在,解决你的问题:
更改方法签名,以公共无效verifymarks(双[,]引号)
,并在方法改变任何使用标记[X] [Y]
到标记[X,Y]
。
Change your method signature to public void verifymarks(double[,] marks)
and in the method change anything that uses marks[x][y]
to marks[x,y]
.
这篇关于双区别[*,*]翻番[] []在C#的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!