c# - Removing element from collection caused removing it from all related objects/collections -


here code c#

 list<element> tmpelementsx = new list<element>();  tmpelementsx = tmpelements;  resultselements.add(tmpelementsx);  element ee = element;  tmpelements.remove(ee); 

when removed ee, leads removed other collection {tmpelementsx },how can keep copy of ee in tmpelementsx . need keep copy ee object inside temporary collection tmpelementsx

the problem objects pointing same memory location, if remove 1 of collections removed other.

you have deep copy (clone) of collection.

this post can useful.


Comments