I’m not sure if my title is correct, but linq should pull the right experts in to help the title and answer the question.
If I have a list of People, how do I return a list of PeopleWrappers minus “Dave” and “Jane”?
query looks like this right now:
List<Person> People = CreatListofPersons();
People.Select(t => new PeopleWrapper(t)).ToArray();
LINQ has a list of extension methods that allow you to filter or project (which you already to with
Select()). In your case you can useWhere()to specify which elements you want to let pass, in your example all persons whose name is neither Dave nor Jane.You typically want to filter as soon as you can, otherwise you will have to iterate and/or project over items you don’t want to have anyway.
Conceptually though, yes, you can put there
where()filter later but in your case you are dealing with aPeopleWrapperafter you project withSelect()– since theWhere()extension method is using this data type as input its condition I don’t think it would make much sense – you would filter people wrappers, not persons.