How can i filter a list of objects using lamda expression?

Posted by Colour Blend on Stack Overflow See other posts from Stack Overflow or by Colour Blend
Published on 2010-03-24T15:44:07Z Indexed on 2010/03/27 11:13 UTC
Read the original article Hit count: 258

Filed under:
|
|

I know i shouldn't have id's with the same value. This is just fictitious, so overlook that.

I have:

List<Car> carList = new List<Car>();
carList.Add(new Car() { id = 1, name = "Honda" });
carList.Add(new Car() { id = 2, name = "Toyota" });
carList.Add(new Car() { id = 1, name = "Nissan" });

I want to use Lamda Expression to retreive all cars that have an id of 1.

Anticipated Result:

-- Id: 1, Name: Honda
-- Id: 1, Name: Nissan

The problem is more filtering an object list based on a foriegn key. Please help me.

© Stack Overflow or respective owner

Related posts about LINQ

Related posts about lambda