Difference between two lists

前端 未结 12 1281
无人共我
无人共我 2020-11-22 13:19

I Have two generic list filled with CustomsObjects.

I need to retrieve the difference between those two lists(Items who are in the first without the items in the sec

12条回答
  •  一生所求
    2020-11-22 13:45

    here is my solution:

        List list1 = new List();
    
        List list2 = new List();
    
        List exceptValue = new List();
    
    foreach(String L1 in List1) 
    {
        if(!List2.Contains(L1)
        {
             exceptValue.Add(L1);
        }
    }
    foreach(String L2 in List2) 
    {
        if(!List1.Contains(L2)
        {
             exceptValue.Add(L2);
        }
    }
    

提交回复
热议问题