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

后端 未结 7 1515
暗喜
暗喜 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

    0 讨论(0)
提交回复
热议问题