How can I make changes to some Copied list that contains reference-type objects without changing the original one

Bakri Bitar

I Have List<PropertyDetails> OriginalList which I clone it to another list by : List<PropretyDetails> CopiedList = OriginalList.ToList();

Now I pass the CopiedList to some method that alters it.

Myproblem is the alterations are reflected to the OriginalList

Marc Selis

A reference type is really a pointer to an object. And because PropertyDetails is also a reference type, copying the list just gives you a new list of pointers that point to the original objects. As Habbib pointed out, you'll have to create copies of the objects in the list, and build a new list that contains these copies.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

How can I monitor when original version of shadow copied assembly changes in app domain

From Dev

How can I rename files and subdirectories in a copied directory based on changes in the original?

From Dev

How can I make a class that type-erases objects until a function is called on them without specifying the list of possible functions up front?

From Dev

How can I manipulate a copy of an array without changing the original array?

From Dev

How can I make a constructor that contains a number of the same objects but if one its empty to ignore it?

From Dev

Excel messes with my formula when copied, how can I stop I stop it changing one part but not the other?

From Dev

How to prevent changing the original object when its reference changes?

From Dev

I have two lists containing the same objects. How do I change one list without changing the other?

From Dev

How can I edit an item in a list without changing the whole list?

From Dev

Why is my original arraylist amended even though I only make changes to my ArrayList within the method without changing the orignal ArrayList

From Dev

How can I use rebase -i so that one commit contains changes of another one?

From Dev

How can I make the proxy type just for implementing some trait for it?

From Dev

How to check if a list of base type contains at least one instance of some child types

From Dev

How can I make an animation on page load to move re-arrange some elements to its original position?

From Dev

How can I make an array without one number of the other array?

From Dev

Can I deserialize generics without a reference to the type?

From Dev

Is there a way I can make a class that accepts multiple objects in a list instead of using Children and adding one by one?

From Dev

How do I use a shader without changing original color

From Dev

Javascript - How can I change one list without modifying the other

From Dev

How can I make it so I click on one smaller image so it changes the larger version of the image?

From Dev

How can I make sure a string contains at least one uppercase letter, one lowercase letter, one number and one punctuation character?

From Dev

how can I make cron run a job right now, for testing/debugging? without changing the schedule!

From Dev

How can I make the draggable window border thicker, without changing the appearance?

From Dev

How can I make a ToggleButton look like a RadioButton without changing its behavior?

From Dev

How can I have changes made to one list affect another, different list?

From Dev

How can I make changes to the boot options?

From Dev

How can I make changes to the boot options?

From Dev

How can I make xrandr changes persist?

From Dev

How can I change a local variable assigned to the value of a global one without changing the global variable?

Related Related

  1. 1

    How can I monitor when original version of shadow copied assembly changes in app domain

  2. 2

    How can I rename files and subdirectories in a copied directory based on changes in the original?

  3. 3

    How can I make a class that type-erases objects until a function is called on them without specifying the list of possible functions up front?

  4. 4

    How can I manipulate a copy of an array without changing the original array?

  5. 5

    How can I make a constructor that contains a number of the same objects but if one its empty to ignore it?

  6. 6

    Excel messes with my formula when copied, how can I stop I stop it changing one part but not the other?

  7. 7

    How to prevent changing the original object when its reference changes?

  8. 8

    I have two lists containing the same objects. How do I change one list without changing the other?

  9. 9

    How can I edit an item in a list without changing the whole list?

  10. 10

    Why is my original arraylist amended even though I only make changes to my ArrayList within the method without changing the orignal ArrayList

  11. 11

    How can I use rebase -i so that one commit contains changes of another one?

  12. 12

    How can I make the proxy type just for implementing some trait for it?

  13. 13

    How to check if a list of base type contains at least one instance of some child types

  14. 14

    How can I make an animation on page load to move re-arrange some elements to its original position?

  15. 15

    How can I make an array without one number of the other array?

  16. 16

    Can I deserialize generics without a reference to the type?

  17. 17

    Is there a way I can make a class that accepts multiple objects in a list instead of using Children and adding one by one?

  18. 18

    How do I use a shader without changing original color

  19. 19

    Javascript - How can I change one list without modifying the other

  20. 20

    How can I make it so I click on one smaller image so it changes the larger version of the image?

  21. 21

    How can I make sure a string contains at least one uppercase letter, one lowercase letter, one number and one punctuation character?

  22. 22

    how can I make cron run a job right now, for testing/debugging? without changing the schedule!

  23. 23

    How can I make the draggable window border thicker, without changing the appearance?

  24. 24

    How can I make a ToggleButton look like a RadioButton without changing its behavior?

  25. 25

    How can I have changes made to one list affect another, different list?

  26. 26

    How can I make changes to the boot options?

  27. 27

    How can I make changes to the boot options?

  28. 28

    How can I make xrandr changes persist?

  29. 29

    How can I change a local variable assigned to the value of a global one without changing the global variable?

HotTag

Archive