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.
效率不高但很清楚:
var inboth = Array1.Where(Array2.Contains);
根据您不区分大小写的评论进行编辑:
inboth = Array1.Where(s => Array2.Contains(s, StringComparer.OrdinalIgnoreCase));
在您发表评论后,
var secondSet = new HashSet<string>(
array2,
StringComparer.CurrentCultureIgnoreCase);
var intersectSequence = array2.Where(secondSet.Contains);