Array indexing

js.mdnq js_adddot+mdng at gmail.com
Mon Dec 3 16:43:29 PST 2012


When accessing an element outside a dynamic array I get an 
exception.

I thought in D arrays will automatically expand themselves?

If not, how do I add an element to an array?

int[] arr = new int[1];
arr[1] = 34; // exception

If I change this to

int[] arr = new int[2];
arr[1] = 34;

Then it works. (similar to C/C++)

But my arrays will be growing and I do not know the final size 
ahead of time.

arr.add(34) does not work.




More information about the Digitalmars-d-learn mailing list