Array indexing
bearophile
bearophileHUGS at lycos.com
Mon Dec 3 16:52:41 PST 2012
js.mdnq:
> When accessing an element outside a dynamic array I get an
> exception.
>
> I thought in D arrays will automatically expand themselves?
D dynamic arrays don't expand themselves "on demand" on array
access, it's not efficient (and I think it's not a very clean
operation, despite some languages do it). On the other hand D
associative arrays grow if you add them key-values.
> arr.add(34) does not work.
To append to a dynamic array use:
arr ~= 34;
Bye,
bearophile
More information about the Digitalmars-d-learn
mailing list