Reputation: 4303
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.
Upvotes: 20
Views: 17780
Reputation: 422172
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 }
Upvotes: 54