use*_*677 14 .net c# linq combinations
我有两个数组:
string[] Group = { "A", null, "B", null, "C", null };
string[] combination = { "C#", "Java", null, "C++", null };
Run Code Online (Sandbox Code Playgroud)
我希望返回所有可能的组合,例如:
{ {"A","C#"} , {"A","Java"} , {"A","C++"},{"B","C#"},............ }
Run Code Online (Sandbox Code Playgroud)
应该忽略null.
Meh*_*ari 37
Group.Where(x => x != null)
.SelectMany(g => combination.Where(c => c != null)
.Select(c => new {Group = g, Combination = c}));
Run Code Online (Sandbox Code Playgroud)
或者:
from g in Group where g != null
from c in combination where c != null
select new { Group = g, Combination = c }
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
9600 次 |
| 最近记录: |