How would I initialize these two lists so that modifying one doesn't modify the other?
- by Brandon
I'm aware of why this is happening, but is there any way to do this without having to implement ICloneable or a Copy() method? Preferably .net 2.0, but 3.5 is fine if it is necessary.
Essentially I'm trying to implement an undo method. In most cases I can just perform the reverse action in the Undo(), but for others that is not possible.
So I want to keep two lists. One for the list of items that I will be modifying, and one for the original, unmodified list of items. This way if I need to do an undo, I just delete the modified items and replace them with the originals. Most of the ways I've tried to assign the _originalItems variable doesn't work, so what would I need to do?
public MyClass(List<SelectedItems> selectedItems)
{
_selectedItems = new List<SelectedItems>(selectedItems);
_originalItems = ??
}