Double jagged array
can double jagged array has dynamic ? how?
2 Answers
Know the answer? Post it. Somebody with the same question will find it here.
Know the answer? Post it. Somebody with the same question will find it here.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend4days leftRegister
Guest UserRank #259 · 9.8K reputationPosted Aug 20, 2014, 3:03 AM EDT
VulpesRank #55 · 29.2K reputationPosted Aug 20, 2014, 3:34 AM EDT
In C#, once you create an array, it's size cannot be changed. Methods such as Array.Resize actually create a new array of the required size and copy the elements of the old array to it.
A 'jagged array' is essentially an array of arrays and, unlike a rectangular array, the size of the constituent arrays need not be the same. However, once they've been created, the size of the constituent arrays cannot be changed.
For example:
double[][] array = new double[2][];
creates a jagged array with 2 array elements.
Each of those array elements can now be individually set:
array[0] = new double[2];
array[1] = new double[3];
They can also be changed to different arrays, including at runtime:
int i = 4;
array[0] = new double[i];
but there's no way in which the current array assigned to array[0] can have its size changed.
If you want something that can dynamically change its size as new elements are added, then use a List
> rather than a jagged array of doubles.