You can also use ToLookup :
var containsLengthLookup = words.ToLookup(w => numbers.Contains(w.Length)); string[] contains = containsLengthLookup[true].ToArray(); string[] notContains = containsLengthLookup[false].ToArray();
If one of them is empty (or the original array is empty), you get an empty string[] .
There is one difference from GroupBy , the search is cached. Therefore, it is more effective if you use it several times, but the information is just a snapshot. If you change words or numbers , this is not reflected in the search.
source share