When using foreach on a List collection, the iterated objects are obviously changed in the collection. I wish to keep a collection "copy" for later use, but this "copy" seems to be changed along with the original list collection.
How can i keep my "copy" collection from being changed when looping through my original list collection?
This is what I've tried so far:
private List<T> _listCopy;
public Constructor(List<T> inputList)
{
_listCopy = new List<T>(inputList);
foreach(var obj in inputList) {
// This changes both inputList and _listCopy.
// How can i keep _listCopy, from being edited as well?
}
}