.net - C# Update List by adding new items, updating existing items and deleting uncommon items in least iteration -
i need update existing list data of new list. shown below:
i have list binded ui element. need update items data of list items of list b without assigning list list b. shown below:
list a: { {id: 1, value: aaa}, {id: 2, value: ddd}, {id: 3, value: ccc}, {id: 4, value: bbb} } list b: { {id: 1, value: zzz}, {id: 5, value: xxx}, {id: 3, value: yyy}, {id: 4, value: bbb} } after updation should have value in list below: list a: { {id: 1, value: zzz}, {id: 5, value: xxx}, {id: 3, value: yyy}, {id: 4, value: bbb} } what best way achieve this?
this should it:
a.removeall(aitem => b.all(bitem => aitem.id != bitem.id)); a.foreach((aitem) => { aitem.value = b.first(bitem => aitem.id == bitem.id).value; }); a.addrange(b.where(bitem => a.all(aitem => aitem.id != bitem.id))); row #1 deletes uncommon items. row #2 updates common items between thetwo lists. , row #3 adds b-unique items.
Comments
Post a Comment