Example: Array1.Intersect(Array2) checks for only distinct elements.
Is there an elegant way using linq to get the result which contains even duplicates? The result should be case-insensitive. Thanks.
Example: Array1.Intersect(Array2) checks for only distinct elements.
Is there an elegant way using linq to get the result which contains even duplicates? The result should be case-insensitive. Thanks.
Not as efficient but clear:
var inboth = Array1.Where(Array2.Contains);
Edit according to your case-insensitive comment:
inboth = Array1.Where(s => Array2.Contains(s, StringComparer.OrdinalIgnoreCase));
Array2 to a HashSet might make things more efficient if there are enough elements in Array1, either way this works.String[]. However, give me a moment.Ordinal passes the turkey test since it behaves like ToUpper(instead of the dangerous ToLower).