本文介绍了计算所有可能的对项目从两份名单?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有两个数组:
的String []组= {A,空,B,空, C,空};
的String [] =组合{C#,Java的,空,C ++,空};
我想返回所有可能的组合,如:
{{A,C#},{A,Java的},{A,C ++},{B,C# },............}
空应该被忽略
解决方案
Group.Where(X =>!x = NULL)
.SelectMany(G => combination.Where(C =>!C = NULL)
。选择(C =>新建{集团= G,组合= C}));
或者
在G组,其中从C在G组合!= NULL
,其中c!= NULL
选择新{组= G,组合= C}
I have two arrays:
string[] Group = { "A", null, "B", null, "C", null };
string[] combination = { "C#", "Java", null, "C++", null };
I wish to return all possible combinations like:
{ {"A","C#"} , {"A","Java"} , {"A","C++"},{"B","C#"},............ }
The null should be ignored.
解决方案
Group.Where(x => x != null)
.SelectMany(g => combination.Where(c => c != null)
.Select(c => new {Group = g, Combination = c}));
Alternatively:
from g in Group where g != null
from c in combination where c != null
select new { Group = g, Combination = c }
这篇关于计算所有可能的对项目从两份名单?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!