2

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.

4

2 回答 2

4

效率不高但很清楚:

var inboth = Array1.Where(Array2.Contains);

根据您不区分大小写的评论进行编辑:

inboth = Array1.Where(s => Array2.Contains(s, StringComparer.OrdinalIgnoreCase));
于 2013-04-29T10:39:58.040 回答
0

在您发表评论后,

var secondSet = new HashSet<string>(
    array2,
    StringComparer.CurrentCultureIgnoreCase);

var intersectSequence = array2.Where(secondSet.Contains);
于 2013-04-29T10:50:08.380 回答