Create copy of a list
November 2, 2016
Posted by on
Sometimes we want to pass a list as parameter to a method, we will do some work on the list but don’t want to affect the origin list.
The code below is not good, as we are passing the orginal reference to the method, all changes will affect the orginal list
Instead, we should do something like:
Pleaes be awared that the second example passed a copy of the list to DoSomeWork, but the elements in the copy still hold reference to the orginal elements. Modifying any object element in the copy list will also change the element in the original.