LINQ Join 2 Lists

后端 未结 4 901
感情败类
感情败类 2020-11-29 07:36

Preface: I don\'t understand what this does:

o => o.ID, i => i.ID, (o, id) => o

So go easy on me. :-)


I have 2 lis

4条回答
  •  余生分开走
    2020-11-29 07:48

    It looks like you don't really need a full-join. You could instead do a semi-join, checking each contact in list 2 to see if it is contained in list 1:

    ContactCollection list3 = list2.Where(c => list1.Contains(c));

    I don't know how big your lists are, but note that this approach has O(nm) complexity unless list1 is sorted or supports fast lookups (as in a hashset), in which case it could be as efficient as O(nlog(m)) or rewritten as a merge-join and be O(n).

提交回复
热议问题