What is a jagged array (in c#)? Any examples and when should one use it....
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.
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.
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.
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.
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];
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With