Can I use Linq's Except() with a lambda expression comparer?

后端 未结 7 1540
暗喜
暗喜 2020-12-01 20:55

I know I can call linq\'s Except and specify a custom IEqualityComparer, but implementing a new Comparer class for each data type seems like an overkill for this purpose. Ca

7条回答
  •  天命终不由人
    2020-12-01 21:30

    Here' is l except r solution, based on a LINQ outer join technique:

    from l in new[] { 1, 2, 3 }
    join r in new[] { 2, 4, 5 }
    on l equals r
    into rr
    where !rr.Any()
    select l
    

    Will yield: 1, 3

提交回复
热议问题