Find the intersection of two lists in linq?

后端 未结 6 469
迷失自我
迷失自我 2020-12-29 01:04

I have list of int A,B. i like to do the following step in linq

list c = new List();

for (int i = 0; i < a.count; i++)
{
    for (i         


        
6条回答
  •  醉梦人生
    2020-12-29 02:04

    As Chris mentions in his comment on the original question, the sample code provided will return duplicates in list c (see his comment for details). Intersect will only return distinct values. To duplicate the behavior of the original sample code, try this:

    var c = (from value in a
             where b.Contains(a)
             select a);
    

提交回复
热议问题