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

Popular posts from this blog

javascript - Clear button on addentry page doesn't work -

c# - Selenium Authentication Popup preventing driver close or quit -

tensorflow when input_data MNIST_data , zlib.error: Error -3 while decompressing: invalid block type -