Remove array element within function

Mike Parker aldacron at gmail.com
Mon Jul 5 13:15:20 UTC 2021


On Monday, 5 July 2021 at 13:10:55 UTC, Rekel wrote:

> ````
>
> But what do you do when you have?:
> ```d
> void function(int[] a){
>     . . .
>     long index = countUntil(a, element);
>     a.remove(index);
> }
> ```
>

```d
void function(ref int[] a) {
     ...
}
```

An array is effectively a length/pointer pair that you are 
passing by value. If you want to do anything that affects either 
property, you need to pass by ref.



More information about the Digitalmars-d-learn mailing list