c# - Remove items from list<a> AND list<b> when a.Foo == b.Bar -
i'm looking elegant way of comparing 2 different list<> collections , removing items in specific field value matches. example: customer object
class customer { string customername; string email; } class employee { string employeename; string employeeid; } list<customer> customers = new list<customers(getcustomers()); list<employee> employees = new list<employees(getemployees());
and know can remove employees list employees in customers list doing this:
employees.removeall(e => customers.any(c.customername == e.employeename));
what know how can remove customers list corresponding employee? possible simple statement or need build out handle this?
what about:
employees.where(e => customers.any(c=> c.customername == e.employeename)).tolist() .foreach(e=> { employees.remove(e); customers.removeall(c => c.customername == e.employeename); });
Comments
Post a Comment