I have 2 lists ListOfItemsToControl
and lstRemoveItems
. I want to remove ListOfItemsToControl
where lstRemoveItems.sItemName
matches ListOfItemsToControl.sItemName
How can this be done ?
I have 2 lists ListOfItemsToControl
and lstRemoveItems
. I want to remove ListOfItemsToControl
where lstRemoveItems.sItemName
matches ListOfItemsToControl.sItemName
How can this be done ?
var names = lstRemoveItems.Select(y => y.sItemName).ToList();
var result = ListOfItemsToControl.Where(x => names.Contains(x.sItemName)).ToList();
var resultList = ListOfItemsToControl.Except(result);
That seems odd but it should work :)
Here's a LINQ one-liner. I haven't tested this, but it should work:
ListOfItemsToControl = ListOfItemsToControl.Where(l => !lstRemoveItems.Any(r => r.sItemName == l.sItemName)).ToList();