Creating 1000 instances
Ferhat Kurtulmuş
aferust at gmail.com
Fri Feb 19 08:43:46 UTC 2021
On Friday, 19 February 2021 at 08:41:06 UTC, Ferhat Kurtulmuş
wrote:
> On Friday, 19 February 2021 at 08:29:36 UTC, Ferhat Kurtulmuş
> wrote:
>> On Friday, 19 February 2021 at 08:04:19 UTC, Виталий Фадеев
>> wrote:
>>> [...]
>>
>> files = new File[]( 1000 );
>> files[] = new File(); // add this
>>
>> Since classes are reference types all instances of files will
>> be the same reference of "new File()", which you probably
>> don't want.
>
> You can do
>
> files[].each!((ref a) => a = new File);
oh, now we can remove brackets
files.each!((ref a) => a = new File);
More information about the Digitalmars-d-learn
mailing list