C# 从两个列表中计算所有可能的项目对?
我有两个阵列:C# 从两个列表中计算所有可能的项目对?,c#,.net,linq,combinations,C#,.net,Linq,Combinations,我有两个阵列: string[] Group = { "A", null, "B", null, "C", null }; string[] combination = { "C#", "Java", null, "C++", null }; 我希望返回所有可能的组合,如: { {"A","C#"} , {"A","Java"} , {"A","C++"},{"B","C#"},............ } 应忽略空值 Group.Where(x => x != null)
string[] Group = { "A", null, "B", null, "C", null };
string[] combination = { "C#", "Java", null, "C++", null };
我希望返回所有可能的组合,如:
{ {"A","C#"} , {"A","Java"} , {"A","C++"},{"B","C#"},............ }
应忽略空值
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 }
谢谢Mehrdad的及时回复。你知道如何有效地进行排列而不仅仅是组合吗?(意思是{“A”、“C”}和{“C”},“A”}将被视为两个独立的项目)?