Questions tagged [jagged-arrays]

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." Use for questions about such arrays. If the array is multidimensional with all elements in each dimension being equal(eg: all rows have the same length), use [multidimensional-arrays] instead.

In computer science, a jagged array, also known as a ragged array, is an array of arrays of which the member arrays can be of different sizes, producing rows of jagged edges when visualized as output. In contrast, C-styled arrays are always rectangular; Arrays of arrays in languages such as Java, PHP, Python (multidimensional lists), Ruby, C#.Net, Visual Basic.NET, Perl, JavaScript, Objective-C, Swift, and Atlas Autocode are implemented as Iliffe vectors (come from here).

In C#, jagged arrays can be created with the following code:

int[][]c;
c=new int[2][]; // creates 2 rows
c[0]=new int[5]; // 5 columns for row 0
c[1]=new int[3]; // create 3 columns for row 1

In C++/CLI, jagged array can be created with the code:

using namespace System;
int main()
{
    array<array<double> ^> ^ Arrayname = gcnew array <array<double> ^> (4);// array contains 4 
    //elements
    return 0;
}

In Python, jagged arrays are not native but one can use list comprehensions to create a multi-dimensional list which supports any dimensional matrix:

 multi_list_3d = [[[] for i in range(3)] for i in range(3)] # [[[], [], []], [[], [], []], [[], [], []]]
 multi_list_5d = [[[] for i in range(5)] for i in range(5)] # [[[], [], [], [], []], [[], [], [], [], []], [[], [], [], [], []], [[], [], [], [], []], [[], [], [], [], []]]
582 questions
-2
votes
2 answers

JSON - Jagged Array Deserialization

I do have a question, it maybe a beginner's question but am not really very familiar with JSON. however, am trying to de-serialize the below JSON using C# Newtonsoft.Json, however, it keeps failing, can anyone please advise how to de-serialize it &…
-2
votes
3 answers

How can I assign array in a jagged array?

I have 3 sets of array they are: a[i], b[j], c[k] and I have to assign them to a jagged array for me to show them to the output. array[0] = new int[3] { a[i] }; array[1] = new int[2] { b[j] }; array[2] = new int[2] { c[k] ]; for (i = 0; i <…
-2
votes
1 answer

Transpose a Jagged List> to a Rectangular One Using Linq C#

My question is very similar to this one here: Rotate - Transposing a List> using LINQ C# Except my testing of the solutions brings to my attention that it works best on even arrays, and not uneven ones. The accepted solution and some…
pmackni
  • 307
  • 3
  • 12
-2
votes
2 answers

init jagged array to zeros

Is there a less verbose way to init this jagged array ? var r = new int[a.Length][]; for (int i=0; i
BaltoStar
  • 8,165
  • 17
  • 59
  • 91
-2
votes
1 answer

C# - Jagged string[][] arrayname into DataTable/DataGridView

I am new to C# programming and topic of operating with jagged array. I have some data stored in my string[][] arrayname and want to show it in datagridview. Will be very grateful if you could advice me on the case.
YutuKAron
  • 3
  • 1
-2
votes
1 answer

C# jagged arryay foreach loop

Can't get my jagged array to output using a nested foreach loop, not sure what I am doing wrong. decimal[][] grades = { new decimal []{255628, 89.6m, 90, 82.9m}, new decimal []{311899, 77.7m, 83.9m, 81.8m, 77}, …
CJack
  • 3
  • 1
-2
votes
2 answers

can access jagged array by foreach loop in c#.net

how to access jagged array by foreach in C#.net? How can do this?
-2
votes
2 answers

Declaring a jagged array in C#

I have a data in a following format: {{{0}},{{1}},{{2,3}},{{1,2},{3,4}},{{5,6},{7,8},{9,10}},.... Is there any way of storing this in a jagged array? The data is large, and I would like to include it directly in the code. I searched internet and it…
user109870
  • 13
  • 1
  • 3
-2
votes
2 answers

Object refrence not set to an instance of an object in array

i am very new to C# programming so my question may sound very silly actualy i am creating an multidimensional string array like public class master { public List user_selected = new List(); public List
too_cool
  • 1,164
  • 8
  • 24
-2
votes
3 answers

Filling a ragged array with a loop in java

I was wondering how it was possible to fill a ragged array with a loop in Java. In my example I want to put Pascals Triangle in the Array. When I try to do it ragged, ( // int [][] hako = new int [n][]; -> as I understand it; it gives a…
NaC114
  • 83
  • 8
-3
votes
1 answer

Allocating Jagged Array C#

It seems like there is no good way to allocate a jagged array in C#. It takes several orders of magnitude longer to allocate a jagged array than to allocate a 2D array. Is there any way around this? Is there a better way? I want the allocation of…
-3
votes
2 answers

Finding the sum of each array in a jagged array C#

Im looking to receive a jagged array of type int[][] and then run through the arrays to find the specific array with the highest sum and then return that sum. Ive done some digging online and haven't found much info about how to sum up each array…
elementmg
  • 234
  • 2
  • 14
-3
votes
1 answer

What is the difference between a multi-dimensional array and a jagged array where all dimensions of the arrays are equal?

I know that a jagged array is an array of arrays where the length of the inner arrays can be of any length. With a multi-dimensional array, the inner arrays all have to be of the same length. But if I have an array of arrays (jagged) where all of…
the man
  • 1,131
  • 1
  • 8
  • 19
-3
votes
1 answer

Jagged array exceeding input c#

` for(int i=0;i
-3
votes
1 answer

jagged array of integers with different dimensionals in each entry

I want to do something like this. The array itself needs to be a single dimensional array but it's elements must hold different multidimensional arrays
Bilal Malik
  • 23
  • 1
  • 9
1 2 3
38
39