Home  >  Article  >  Backend Development  >  What is the difference between multidimensional array and jagged array?

What is the difference between multidimensional array and jagged array?

WBOY
WBOYforward
2023-09-10 12:13:021219browse

What is the difference between multidimensional array and jagged array?

Multidimensional array

Multidimensional array is also called a rectangular array. You can define a 3-dimensional array of integers as -

int [ , , ] val;

Let's see how to define a 2-dimensional array.

int[,] val = new[3,3]

Jagged array

Jagged array is an array of arrays. To access an element from it, just mention the index of that particular array.

Here, we have a jagged array of 5 integer arrays -

int[][] a = new int[][]{new int[]{0,0},new int[]{1,2}, new int[]{2,4},new int[]{ 3, 6 }};

The above is the detailed content of What is the difference between multidimensional array and jagged array?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
This article is reproduced at:tutorialspoint.com. If there is any infringement, please contact admin@php.cn delete