计算所有可能的对项目的两个列表?(Calculate all possible pairs of i

2019-07-03 16:06发布

我有两个数组:

string[] Group = { "A", null, "B", null, "C", null };

string[] combination = { "C#", "Java", null, "C++", null }; 

我想返回所有可能的组合,如:

{ {"A","C#"} , {"A","Java"} , {"A","C++"},{"B","C#"},............ }

空应该被忽略。

Answer 1:

Group.Where(x => x != null)
     .SelectMany(g => combination.Where(c => c != null)
                                 .Select(c => new {Group = g, Combination = c}));

或者:

from g in Group where g != null
from c in combination where c != null
select new { Group = g, Combination = c }


文章来源: Calculate all possible pairs of items from two lists?