Home > Backend Development > C++ > C# Multidimensional Arrays: `double[][]` vs. `double[,]` – What's the Difference?

C# Multidimensional Arrays: `double[][]` vs. `double[,]` – What's the Difference?

Patricia Arquette
Release: 2025-01-24 11:12:11
Original
1040 people have browsed it

C# Multidimensional Arrays: `double[][]` vs. `double[,]` – What's the Difference?

C# multi -dimensional array:

and double[][] double[,] C# offers two ways to declare multi -dimensional arrays: array of array (

) and a unified two -dimensional array (

). double[][] double[,] <.> 1. The array of the array (

)

double[][] When the array of the array is declared, each element in the external array is a separate array. This allows the creation of a sawtooth, where the internal array can have different lengths.

<.> 2. Two -dimensional array (

)
// 声明一个数组的数组
double[][] ServicePoint = new double[10][];

// 为内部数组分配不同的长度
ServicePoint[0] = new double[13];
ServicePoint[1] = new double[20];
Copy after login

On the contrary, the two -dimensional array has a unified structure, all of which are the same type and have the same amount of dimension. double[,]

<<> Grammar error

// 声明一个二维数组
double[,] ServicePoint = new double[10, 9];

// 错误:无法将一维数组赋值给二维数组的行/列
double[] d = new double[9];
ServicePoint[0] = d; // 此行会报错
Copy after login

In the given code, the error of the first line is caused by the incorrect grammar of the array of the array of the array. The correct grammar is: double[][] The reason for the error

When the array of the array is declared, the length of the external array is specified only during the structure period. The length of the internal array is determined when assigned its value.

The above is the detailed content of C# Multidimensional Arrays: `double[][]` vs. `double[,]` – What's the Difference?. For more information, please follow other related articles on the PHP Chinese website!

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Articles by Author
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template