Reputation: 2748
The code below works successfully to remove if a value exists in a list. How do I add a where clause such that only for list items where sType = "File"
MyGlobals.lstNewItems.RemoveAll(item => item.sItemName == rows[i].Cells[0].Value.ToString());
Pseudo Code for what i want
MyGlobals.lstNewItems.Where(y => y.sType == "File").RemoveAll(item => item.sItemName == rows[i].Cells[0].Value.ToString());
Upvotes: 0
Views: 1430
Reputation: 203827
If you want to remove all of the items where both conditions are true, then simply AND them together:
MyGlobals.lstNewItems.RemoveAll(item =>
item.sItemName == rows[i].Cells[0].Value.ToString()
&& item.sType == "File");
Upvotes: 5