tags:

views:

88

answers:

3

Hi there, wondering if anyone can help. This works, but I was wondering how it would look in Lambda instead (Just curious !)

Codes is simply an array of id's and each item has a code...

        var qry = from i in items
                where Codes.Contains(i.Code)
                select i;

        return qry.ToList();

Thanks Andrew.

+12  A: 
return items.Where(i => Codes.Contains(i.Code)).ToList();
Adam Robinson
+4  A: 
var qry = items.Where(i => Codes.Contains(i.Code));
Bob
A: 

If items is a List<Item>, you can save yourself the ToList() call like so:

var qry = items.FindAll(i => Codes.Contains(i.Code));
Martin R-L