Both of my lists are being modified and am trying to avoid this behaviour...
What's the gotcha here?
I have a 'large' list and I want to remove all items that are present in the the itemsToRemoveList but without having it modify the original list.
I've simplified the example code..
List<string> aList = new List<string>(){"My","name","is", "jeff"}; // cached full list
List<string> bList = aList; // initial copy
List<string> itemsToRemoveList = new List<string>(){"jeff"};
bList.RemoveAll(itemsToRemoveList.Contains); // remove only from copy
foreach (string s in aList)
{
Console.Write(s + " "); // expect "my name is jeff"
}
Console.WriteLine();
foreach (string s in bList)
{
Console.Write(s + " "); // expect "my name is"
}
// however this modifies both collections.
Console.ReadLine();