Search code examples
c#listremoveall

Displaying values that were removed from list


Hello I'm currently removing elements from list doing this:

candidateList.RemoveAll(x => versionslist.Any(y => y.Name == x.Name && y.Parent.Name == x.Parent.Name));

I want to see what is actually being removed so i can compare it after with versionList to see why not all the values are being removed. I know this because version list is a sublist of canadidateList and after the removeall the math doesnt add up.


Solution

  • There is no built in way to see what items are removed from list.

    If you need it for debugging - one easy way would be to just use .Where(...).ToList() with the same condition before call to .RemoveAll and inspect the result.

    If you need that information at run-time consider using ObservableCollection<T> instead of regular list and listen to "removed" notifications.