1
Reply

What is a Jagged Array in C#?

Rahul  Pandey

Rahul Pandey

11y
1.6k
0
Reply

    A jagged array is an array of arrays in which the length of each array can differ. Thus, a jagged array can be used to create a table in which the lengths of the rows are not the same.Jagged arrays are declared by using sets of square brackets to indicate each dimension. For example, to declare a two-dimensional jagged array, you will use this general form: type[ ] [ ] array-name = new type[size][ ]; Here, size indicates the number of rows in the array. The rows, themselves, have not been allocated. Instead, the rows are allocated individually. This allows for the length of each row to vary. For example, the following code allocates memory for the first dimension of jagged when it is declared. It then allocates the second dimensions manually. int[][] jagged = new int[3][]; jagged[0] = new int[4]; jagged[1] = new int[3]; jagged[2] = new int[5]; Jagged arrays are not used by all applications, but they can be effective in some situations. For example, if you need a very large two-dimensional array that is sparsely populated (that is, one in which not all of the elements will be used), then a jagged array might be a perfect solution. for learning more about c# you can refer this link c# interview questions