I am trying to figure out why my delegate function does not work, any help would be appreciated, this is probably a small issue but I have been working on it for a while and connot figure it out, my code:
//remove all matching people from this list
public void RemovePeopleFromLookup(Predicate<PeopleDTO> _people)
{
//Lookup is an internal readonly ICollection of PeopleDTO
Lookup.RemoveAll(_people);
}
//call the method as below:
//data is a collection of PeopleDTO
mylookupobj.RemovePeopleFromLookup(x => data.Any(y => y.Name == x.Name && x.Type == FieldElement.Strange));
For some reason all people get removed from this lookup, this is not correct, I only want to remove the people who are
- Strange
- who DONOT exist in the data collection
EDIT:
The data collection can be an object of different types -> strange, noisy etc…
The mylookupobj.Lookup data collection is similar to the data collection and contain contain multiple types hence why I wrote my query that way
EDIT2: I missed out this information which may be very important…
public class PersonDTO
{
//Name
//Type
//Age
//Desc
}
Inside the mylookupobj.Lookup – all the properties contain data, however inside the data collection only the Name + Type is present.
A simpler and more efficient predicate would be:
But I admit I don’t see a principal problem with either.
Edit: seems 1 of the conditions has to be inverted.