Using .length returns incorrect number of elements

Chris M. chrismohrfeld at comcast.net
Sun Aug 19 16:07:52 UTC 2018


On Sunday, 19 August 2018 at 16:03:06 UTC, QueenSvetlana wrote:
> On Sunday, 19 August 2018 at 15:53:25 UTC, Chris M. wrote:
>> On Sunday, 19 August 2018 at 15:49:18 UTC, Chris M. wrote:
>>> On Sunday, 19 August 2018 at 15:44:07 UTC, QueenSvetlana 
>>> wrote:
>>>> [...]
>>>
>>> auto appendNumber = appender(arrayofNumbers);
>>>
>>> This returns a separate object. You probably meant to put 
>>> this for the last line
>>>
>>> writeln(appendNumber.length);
>>
>> Whoops
>>
>> writeln(appendNumber.data.length);
>>
>> https://run.dlang.io/is/4aNx1l
>
> New to d programming here :D Bare with me.
>
> The object that is returned by appendNumber.data is an array 
> reflecting the elements I added using appendNumber correct? So 
> I would have the call length on appendNumber.data instead of 
> the original array?

Yes, the .data field gives the array you're working on.


More information about the Digitalmars-d-learn mailing list