0% found this document useful (0 votes)
248 views

Jagged Array

A jagged array is an array whose elements are arrays of different dimensions and sizes. It is an array of arrays that allows each nested array to have a different length. Jagged arrays are declared by specifying the size of the outer array and initializing each inner array element to an array of the appropriate length. Individual elements within the inner arrays can then be accessed and assigned values.

Uploaded by

Raj Akhani
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
248 views

Jagged Array

A jagged array is an array whose elements are arrays of different dimensions and sizes. It is an array of arrays that allows each nested array to have a different length. Jagged arrays are declared by specifying the size of the outer array and initializing each inner array element to an array of the appropriate length. Individual elements within the inner arrays can then be accessed and assigned values.

Uploaded by

Raj Akhani
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 7

JAGGED ARRAY

A jagged array is an array whose elements are arrays. The elements of a jagged array can be of different dimensions and sizes. A jagged array is sometimes called an "array of arrays." C# provides the ability to create a special type of two dimensional array called as Jagged Array. In simple terms, a jagged array is an array of arrays. A jagged array is a little different than a two dimensional array, the major difference being that in a jagged array the length of each array may differ. Thus, a jagged array can be used to create a table in which the lengths of the rows are not the same

The following is a declaration of a singledimensional array that has three elements, each of which is a single-dimensional array of integers: Declaring a jagged array:
data_type [][] array_name = new data_type[size][]; int[][] jaggedArray = new int[3][];

Before you can use jaggedArray, its elements must be initialized. You can initialize the elements like this:
jaggedArray[0] = new int[5]; jaggedArray[1] = new int[4]; jaggedArray[2] = new int[2];

Each of the elements is a single-dimensional array of integers. The first element is an array of 5 integers, the second is an array of 4 integers, and the third is an array of 2 integers. It is also possible to use initializers to fill the array elements with values, in which case you do not need the array size. For example:
jaggedArray[0] = new int[] { 1, 3, 5, 7, 9 }; jaggedArray[1] = new int[] { 0, 2, 4, 6 }; jaggedArray[2] = new int[] { 11, 22 };

A jagged array is an array of arrays, and therefore its elements are reference types and are initialized to null. You can access individual array elements like these examples: // Assign 77 to the second element ([1]) of the first array ([0]):
jaggedArray3[0][1] = 77;

// Assign 88 to the second element ([1]) of the third array ([2]):


jaggedArray3[2][1] = 88;

This example builds an array whose elements are themselves arrays. Each one of the array elements has a different size.

You might also like