SImplifying with LINQ - Basic selection

Posted by baron on Stack Overflow See other posts from Stack Overflow or by baron
Published on 2010-03-31T00:51:11Z Indexed on 2010/03/31 0:53 UTC
Read the original article Hit count: 303

Filed under:
|
|

Hello

foreach (var person in peopleList.Where(person => person.FirstName == "Messi"))
{
        selectPeople.Add(person);
}

I am just wondering if there is any way to simplify this using LINQ.

Like rather than look at all the people I was trying to use LINQ to just fill a list with the "Messi"'s... was trying something like...

var selectPeople = peopleList.Select(x=>x.FirstName=="Messi");

Then I could just add everyone in that list without a check. But it doesn't quite work as planned.

Maybe there's no point simplifying that expression. But the question seemed worthwhile just to strengthen my LINQ knowledge.

© Stack Overflow or respective owner

Related posts about LINQ

Related posts about c#