Using Linq Except not Working as I Thought

后端 未结 5 1416
梦如初夏
梦如初夏 2020-11-28 10:26

List1 contains items { A, B } and List2 contains items { A, B, C }.

What I need is to be returned { C }

5条回答
  •  时光说笑
    2020-11-28 11:24

    If you are storing reference types in your list, you have to make sure there is a way to compare the objects for equality. Otherwise they will be checked by comparing if they refer to same address.

    You can implement IEqualityComparer and send it as a parameter to Except() function. Here's a blog post you may find helpful.

    edit: the original blog post link was broken and has been replaced above

提交回复
热议问题