日期:2014-05-17  浏览次数:20790 次

错在哪了?为何会发生重复
本帖最后由 zhenghq1001 于 2013-01-06 14:19:52 编辑
根据target从src里找到包含target一样(不管顺序)的元素

List<string> target: {112,113,112,133,223,233}
List<string> src: {313,134,228,323,332,121,237,232,221,912,332,......}

然后对src用类似"List<string> grp = Trend.Cell(1, c).Text.Select(a => a.ToString()).ToList()"
进行转化

int k = 1;
for (s = 0; s < src.Count; s++)
{
   for (t = 0; t < target.Count; t++)
   {
        if (src[s].Distinct().Count() == 2 && src[s].Intersect(target[t]).Count() == 2)
        {
             表格单元格(k,1).Text = src(s).ToString();
        }
        k++
   }
}


查询的结果会显示两次,如下图,这是怎么回事呢?



------解决方案--------------------


根据你的判断语句
src[s].Distinct().Count() == 2 && src[s].Intersect(target[t]).Count() == 2

那么target里的 223,233 对应src里的232,都是一样的,所以会出现两次
加入break之后,表示223,233只要有1个与232一样,就退出循环了