c# - Filter Linq EXCEPT on properties -


this may seem silly, examples i've found using except in linq use 2 lists or arrays of strings or integers , filters them based on matches, example:

var excludes = users.except(matches); 

i want use exclude keep code short , simple, can't seem find out how following:

class appmeta {     public int id { get; set; } }  var excludedappids = new list<int> {2, 3, 5, 6}; var unfilteredapps = new list<appmeta>                          {                            new appmeta {id = 1},                            new appmeta {id = 2},                            new appmeta {id = 3},                            new appmeta {id = 4},                            new appmeta {id = 5}                          } 

how list of appmeta filters on excludedappids?

try simple query

var filtered = unfilteredapps.where(i => !excludedappids.contains(i.id));  

the except method uses equality, lists contain objects of different types, none of items contain equal!


Comments