I have two lists will say ListA and ListB. I need to loop through ListB and compare ID's to ListA. If there is a match then I need to remove that item from ListB and replace it with the matching item/object from ListA.
I've been looking at THIS article. I've also had a look at Intersect. But I'm really not sure on how to get this to work with Linq.
Here is my code:
ListB is a query generated else where and passed in
var itemsForListA = Context.Set<Item>().AsQueryable();
var ListA = from i in itemsForListA
where i.ReplacementItemID != null
&& (i.ItemStatus == "DISC" || i.ItemStatus == "ACT"
&& i.StoreID == null)
select i;
foreach (var i in ListB)
{
ListB = ListA.Where(x => x.Id == ListA.Id);
}
I thought I could do something like that. Do I first have to find the id in ListB and remove it then append on the new id from ListA to B?