Removing elements from dynamic array

anonymous via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Sun Aug 9 13:37:44 PDT 2015


On Sunday, 9 August 2015 at 20:23:00 UTC, Reflexive wrote:
> I see that remove() removes the value of the element but keeps 
> the same size of the array, and replace the value by a new one 
> at the end. The method :
>
> class sabot{
> 	card[] sabotarray ;
>
> 	(...)
>
> 	card getCard(){
> 		card returncard = this.sabotarray[0] ;
> 		this.sabotarray.remove(0) ;
> 		return returncard ;
> 	}

`remove` doesn't update the passed array, but it returns a slice 
of it that doesn't include the removed element. To update the 
original array, assign the result of `remove` to it:

this.sabotarray = this.sabotarray.remove(0);


More information about the Digitalmars-d-learn mailing list