Custom intersect in lambda

后端 未结 4 776
离开以前
离开以前 2021-02-08 01:37

I would like to know if this is possible to solve using a lambda expression:

List listOne = service.GetListOne();
List listTwo = service.Ge         


        
4条回答
  •  慢半拍i
    慢半拍i (楼主)
    2021-02-08 02:30

    var result = from one in listOne
                 join two in listTwo on one.Id equals two.Id
                 where one.SomeKey != two.SomeKey
                 select one;
    

    Update: It seems that some people feel that this is not answering the question, as it supposedly is not using lambdas. Of course it is, it's just using the friendly query syntax.

    Here's the exact same code, only less readable:

    var result = 
        listOne.Join(listTwo, one => one.Id, two => two.Id, (one, two) => new { one, two })
               .Where(p => p.one.someKey != p.two.someKey)
               .Select(p => p.one);
    

提交回复
热议问题