score:1

Accepted answer

now that this has been clarified, the question is basically this:

  • combine all elements from list a and list b, and if there are any duplicates, keep the one with the newest lastgameplayed.

i would do this with a grouping:

var players = from p in lista.concat(listb)
              group p by p.id into g
              select g.orderbydescending(x => x.lastgameplayed).first();

if performance is an issue, there are "faster" ways to write this, but i would start with this.

score:0

you can write an o(n log n) solution by building a set from list2 then overwriting (or inserting) items with list1, then converting that set back to a list.

if the lists are already sorted, you could do it o(n) by merging by hand.

score:2

you should be able to use the linq enumerable extension concat and exept to achieve this.

lista.concat(listb.except(lista);

this will remove items in b that match a, and them add the result to a.

you will have to write an iequalitycomparer which compares by id.

documentation for theses methods can be found here:

msdn enumerable extensions

iequalitycomparer documentation can be found here:

msdn iequalitycomparer


Related Query

More Query from same tag