Suppose I have the following arrays:
List<int[]> numbers = new List<int[]>();
numbers.Add(new int[] { 1, 2, 3 });
numbers.Add(new int[] { 3, 4, 5 });
numbers.Add(new int[] { 5, 6, 7 });
int[] numbersToFind = new int[] { 4, 5, 6 };
I want to find which of the numbers
elements contains one/more of the values in numbersToFind
, is there an easy way of doing this with LINQ? That is, some code that would return a IEnumerable<int[]>
containing an int[]{3,4,5}
and int[]{5,6,7}
in the above example.
How can this be done?
numbers.Where(array => array.Any(value => numbersToFind.Contains(value)));
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With