score:0

one option is to do an union operation, by specifying an equalitycomparer. if the order is important, you can do an orderby operation at the end.

class textidcomparer : equalitycomparer<text> {
    public override bool equals(text x, text y) => x.id == y.id;
}

var result = listb.union(lista, new textidcomparer()).orderby(x => x.id)

score:2

it might be more efficient to convert listb to a dictionary first: var dictb = listb.todictionary(x=> x.id)

then you can write

var result = lista.select(x => dictb.trygetvalue(x.id, out var b) ? b : x)

upd rewrote taking comment suggestions into account

score:3

you can try looking for id within listb:

var result = lista
  .select(a => listb.firstordefault(b => b.id == a.id) ?? a);

here for each a within lista we try to find corresponding by id (b.id == a.id) item within listb. if no such item is found we just return lista item: ?? item

in case of .net 6 you can use overloaded .firstordefault version (we can pass a as a default value):

var result = lista
  .select(a => listb.firstordefault(b => a.id == b.id, a));

Related Query

More Query from same tag