.dup vs operation on all elements

Goksan iamgoksan at gmail.com
Mon Dec 3 20:07:24 UTC 2018


Are there any differences between these 2 methods of copying 
elements?

double[] array = [ 1, 20, 2, 30, 7, 11 ];

// Non dup
double[6] bracket_syntax_dup = array;
bracket_syntax_dup[] = array;
bracket_syntax_dup[0] = 50;

// Dup
double[6] normal_dup = array.dup;
normal_dup[0] = 100;

OUTPUT: (array, bracket_syntax_dup and normal_dup respectively):
[1, 20, 2, 30, 7, 11]
[50, 20, 2, 30, 7, 11]
[100, 20, 2, 30, 7, 11]


More information about the Digitalmars-d-learn mailing list