Hello everyone, I am having a little problem with C#
I'd rather illustrate my point with a little piece of code:
List<int> List1, List2;
List1 = new List<int>();
List1.AddRange(new int[] { 1, 2, 3, 4, 5, 6, 7, 8, 9 });
List2 = List1;
List2.Reverse();
In the above code, after List2 is .Reversed(), the items of List1
are ALSO reversed!
I am guessing that
List2 = List1
mimics something like pointers in plain C,
ie List2 points to List1 (by reference), but
I thought that using this command I would initiate List2,
and basically "copy" List1 to List2, with List2 being an
independent entity.
Is this behaviour normal or am I missing something here?
Also, which approach do you propose to achieve what I am
looking for here?
Currently I am using
List2.AddRange(List1)
instead of the above statement, which seems
to take care of the "dependency" issue