views:

1052

answers:

1

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#"},............ }

(null should be ignored).

using LINQ.

Help please.

+14  A: 
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 }
Mehrdad Afshari
Thanks Mehrdad for immediate response.