Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

difference between double[*,*] to double[][] in c#

Tags:

c#

i used

double [,] marks=new double[26,5] 
int[] function = object.verify(marks) 

public void verifymarks(double[][] marks)

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

like image 358
user1700961 Avatar asked Jul 22 '13 19:07

user1700961


People also ask

What is the difference between double and long double in C?

The difference is the size. They may be the same, or a long double may be larger. Larger meaning that it can hold greater (and smaller) values and with higher precision. The difference is that any type with long is more precise and has a greater range then the type itself without long because it uses more bytes.

What's the difference between float double and long double?

They have different sizes and precision. Basically all of them represent the decimal values such as 3.14 The main difference between them is that in float we can store values upto 4 bytes (6 places after decimal point) Double upto 8 bytes And long double even more than float and double.

What is difference between double and double?

Double is an object and double is a primitive data type.

What's the difference between float and double precision?

Difference in Precision (Accuracy) float and double both have varying capacities when it comes to the number of decimal digits they can hold. float can hold up to 7 decimal digits accurately while double can hold up to 15.


2 Answers

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

A way to get around it would be to use nullable ints.

Now, to solve your problem:

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].

like image 65
It'sNotALie. Avatar answered Sep 20 '22 21:09

It'sNotALie.


double[][] is called a Jagged array. It is an array of array (the same way you could create a list of list). With this structure you can specify a different size for each sub-array.

For exemple:

double[][] jaggedArray = new double[2][];
jaggedArray[0] = new double[5];
jaggedArray[1] = new double[151];

The other writing double[,] is a 2D array (Multidimensional array in general). You can see it as a table.

A very handy feature of multidimensional array is the initialization:

string[,] test = new string[3, 2] { { "one", "two" }, 
                                    { "three", "four" },
                                    { "five", "six" } };
like image 23
Cédric Bignon Avatar answered Sep 18 '22 21:09

Cédric Bignon