Linq to return ALL pairs of elements from two lists?

前端 未结 7 1570
日久生厌
日久生厌 2021-01-17 10:56

Given lists l1 = {1, 2} and l2 = {4, 5, 6 } I want to get a new list that has elements:

rez = { {1, 4}, {1, 5}, {1, 6}, {2, 4}, {2,         


        
7条回答
  •  渐次进展
    2021-01-17 11:38

    Great article by Eric Lippert - see links in other answers. What's even better, this was the first try I did before looking at the answers on this page :)

    In short:

    var rez = 
        from e1 in l1
        from e2 in l2 
        select new {e1, e2};
    

提交回复
热议问题