Cannot convert from double [] [] to double [*, *]

I have a code that looks (more or less):

public void INeedHolidaysNow(double[,]){ //... Code to take a break from coding and fly to Hawaii } double[][] WageLossPerVacationDay = new double[10][5]; INeedHolidays(WageLossPerVacationDay); // >>throws the Exception in the Title 

I found a solution on this post , which is to cyclize, not try wild casting

So my question is: WHY? what happens behind the scenes in memory allocation, which prevents what it might seem - at least at first glance, to be a valid throw? I mean structurally, both expressions seem completely identical. What am I missing here?

EDIT: I have to use "double [] []" as it is provided by an external library.

+6
arrays c #
source share
4 answers

One of them is a gear array, the other is one large block.

double[][] - an array containing double arrays. Its shape is not necessarily rectangular. In c, its term is similar to a double**

double[,] is only one large block of memory, and it is always rectangular. In terms of c, it's just double *, where you use myArray[x+y*width] to access the element.

+10
source share

One is called a multidimensional array ( double[*,*] ), and the other is called a jagged array ( double[][] ).

Here is a good discussion of the differences between the two.

What is the difference between a multidimensional array and an array of arrays in C #?

+6
source share

Quite simply, the arrays of arrays [,] (2D arrays) and [][] (jagged arrays) do not match.

Array A [,] can be visually represented by a rectangle (therefore, it is also known as a rectangular array), and array [][] is a 1D array containing other 1D arrays.

It would not make sense to be able to throw one at another.

+2
source share

You should define your double array as follows:

 double[,] WageLossPerVacationDay = new double[3, 5]; 

Then it should work!

Hth

0
source share

All Articles