Linq to return ALL pairs of elements from two lists?

前端 未结 7 1508
日久生厌
日久生厌 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:40

    something like this will do what you are looking for.

    var l1 = new List{1,2};
    var l2 = new List{4,5,6};
    
    var p = from n in l1
            from m in l2
            select new { Fst = n, Scd = m };
    

    with this answer your tuples {x,y} are an anonymous type.

提交回复
热议问题