Home > Backend Development > C++ > C# Multidimensional Arrays: What's the Difference Between `[][]` and `[,]`?

C# Multidimensional Arrays: What's the Difference Between `[][]` and `[,]`?

Susan Sarandon
Release: 2025-01-24 11:27:11
Original
850 people have browsed it

C# Multidimensional Arrays: What's the Difference Between `[][]` and `[,]`?

The multi -dimensional array in the c#

and [][] [,] When creating a multi -dimensional array in C#, there is a difference between

and

grammar. [][] [,] The array of an array (

)

[][]

This grammar creates a reference array of an array. Each element of the array can have different lengths to create a jagged array.

double[][] ServicePoint = new double[10][]; Unified two -dimensional array (

)

[,] This grammar creates a unified two -dimensional array, of which each element is the same size. Unlike the sawtooth array, it requires specified rows and indexes during the assignment period.

Why (1) report an error

double[,] ServicePoint = new double[10, 9];

The grammatical error is because C# requires only one index when creating an array in the array. The second index is specified when it is assigned to each element.

Why

Failure in (2)

Because is a unified two -dimensional array, the assignment must specify and indexes at the same time.

It is meaningless, because it tries to access one -dimensional array in the two -dimensional array. double[][] ServicePoint = new double10;

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

source:php.cn
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