Double jagged array
can double jagged array has dynamic ? how?
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
VulpesPosted Aug 20, 2014, 7:34 AM
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.
Guest UserPosted Aug 20, 2014, 7:03 AM