Nested “from” LINQ query expressed with extension methods

后端 未结 3 890
轻奢々
轻奢々 2020-11-27 17:35

How can I write this LINQ query by using the extension method syntax?

var query = from a in sequenceA
            from b in sequenceB
            select ...;         


        
3条回答
  •  执念已碎
    2020-11-27 18:01

    var query = sequenceA.SelectMany(a => sequenceB.Select(b => ...));
    

    Edit: as pointed out by Eric Lippert in the comments, this gives the same results, but is intentionally not how it is translated internally. See his answer for another way to call SelectMany, which does correspond to the original. Also, added the omitted b => for clarity.

提交回复
热议问题