Friday, December 31, 2010

Linq queries vs Lambda queries


foreach (var id in _clientIds)
{
items.AddRange(
clients.Where(x => x.ClientID == id)
);
}

// rest of the clients
items.AddRange(
clients.Where(x => !_clientIds.Contains(x.ClientID))
);

VS


foreach (var id in _clientIds)
{
items.AddRange(from c in clients
where c.ClientID == id
select c);
}

// rest of the clients
items.AddRange(from c in clients
where !_clientIds.Contains(c.ClientID)
select c);

No comments: