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
Patricia ArquetteOriginal
2025-01-24 11:12:11977browse

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 (

)
<code class="language-C#">// 声明一个数组的数组
double[][] ServicePoint = new double[10][];

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

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

<code class="language-C#">// 声明一个二维数组
double[,] ServicePoint = new double[10, 9];

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

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:
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