jeudi 27 août 2015

Remove unmatched records from list

I have a class ABC like this

public class ABC{
public int Id {get;set;}
public int UserCount {get;set;}
}

Now I add following records to a list of type ABC

List<ABC> lstABC = new List<ABC>();
lstABC.Add(new ABC(){Id=1,UserCount=5});
lstABC.Add(new ABC(){Id=2,UserCount=15});
lstABC.Add(new ABC(){Id=3,UserCount=3});
lstABC.Add(new ABC(){Id=4,UserCount=20});
lstABC.Add(new ABC(){Id=5,UserCount=33});
lstABC.Add(new ABC(){Id=6,UserCount=21});

I've another list of type int

List<int> lstIds = new List<int>();
lstIds.Add(1);
lstIds.Add(3);
lstIds.Add(4);

Now i want to remove all the items from lstABC whose Id's do not match in lstIds without using any loops. What is the most optimized way to do this?

Aucun commentaire:

Enregistrer un commentaire