Difference between two lists

前端 未结 12 1300
无人共我
无人共我 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条回答
  •  Happy的楠姐
    2020-11-22 13:40

    List _list_DF_BW_ANB = new List();    
    List _listA = new List();
    List _listB = new List();
    
    foreach (var itemB in _listB )
    {     
        var flat = 0;
        foreach(var itemA in _listA )
        {
            if(itemA.ProductId==itemB.ProductId)
            {
                flat = 1;
                break;
            }
        }
        if (flat == 0)
        {
            _list_DF_BW_ANB.Add(itemB);
        }
    }
    

提交回复
热议问题