Compare the difference between two list

后端 未结 3 1378
粉色の甜心
粉色の甜心 2020-12-10 02:15

I\'am trying to check the difference between two List in c#.

Example:

List FirstList = new List         


        
3条回答
  •  忘掉有多难
    2020-12-10 03:21

    You can use Enumerable.Intersect:

    var inBoth = FirstList.Intersect(SecondList);
    

    or to detect strings which are only in one of both lists, Enumerable.Except:

    var inFirstOnly = FirstList.Except(SecondList);
    var inSecondOnly = SecondList.Except(FirstList);
    

    To get your ThirdList:

    List ThirdList = inSecondOnly.ToList();
    

提交回复
热议问题