添加到D中的动态数组?

Sam*_*mpa 2 d

我现在必须遗漏一些明显的东西,但我无法弄清楚如何在D中向动态数组中添加元素.

我试过这个,没有成功:

string[] links;
foreach(link; someOtherArray) {
    // Do something with link ...
    links[] = link; // Trying here to add to the links array
}
Run Code Online (Sandbox Code Playgroud)

还有这个:

string[] links;
int i = 0;
foreach(link; someOtherArray) {
    // Do something with link ...
    links[i] = link; // Trying here to add to the links array
    i++;
}
Run Code Online (Sandbox Code Playgroud)

这样做的正确方法是什么?

Ada*_*ppe 9

使用concat运算符:a~b或a~ = b;

string[] links;
foreach(link; arr) {
     links ~= link;
}
Run Code Online (Sandbox Code Playgroud)

右侧可以是单个元素或另一个阵列.