Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is a jagged array?

What is a jagged array (in c#)? Any examples and when should one use it....

like image 219
ACP Avatar asked Apr 05 '10 03:04

ACP


People also ask

What do you mean by jagged array?

A jagged array is an array whose elements are arrays, possibly of different sizes. A jagged array is sometimes called an "array of arrays." The following examples show how to declare, initialize, and access jagged arrays.

What are jagged arrays used for?

Jagged arrays are a special type of arrays that can be used to store rows of data of varying lengths to improve performance when working with multi-dimensional arrays. An array may be defined as a sequential collection of elements of the same data type.

What is jagged array in C++?

Jagged array is array of arrays such that member arrays can be of different sizes, i.e., we can create a 2-D array but with a variable number of columns in each row. These type of arrays are also known as Jagged arrays.

What are jagged array in Java?

Jagged array is a multidimensional array where member arrays are of different size. For example, we can create a 2D array where first array is of 3 elements, and is of 4 elements.


1 Answers

A jagged array is an array of arrays.

string[][] arrays = new string[5][]; 

That's a collection of five different string arrays, each could be a different length (they could also be the same length, but the point is there is no guarantee that they are).

arrays[0] = new string[5]; arrays[1] = new string[100]; ... 

This is different from a 2D array where it is rectangular, meaning each row has the same number of columns.

string[,] array = new string[3,5]; 
like image 184
Anthony Pegram Avatar answered Sep 29 '22 05:09

Anthony Pegram