c# - Select only such items that contain any element in int array -
assume have class:
public class item {     ...     public ienumerable<int> clientsids { get; set; } }   and following code:
list<item> items = getitems(); int[] ids = getids();   now need select such items contain element in ids int array. how can it?
well simple where should it:
var filtereditems = items.where(item =>                        item.clientids.any(ids.contains)).tolist();   i don't see need extension method here, of course encapsulate it:
public static ienumerable<item> filteritems(this ienumerable<item> source, ienumerable<int> filter) {     return source.where(item => item.clientids.any(filter.contains)); }      
Comments
Post a Comment