19

私は2つの配列を持っています:

string[] Group = { "A", null, "B", null, "C", null };

string[] combination = { "C#", "Java", null, "C++", null }; 

次のようなすべての可能な組み合わせを返したいと思います。

{ {"A","C#"} , {"A","Java"} , {"A","C++"},{"B","C#"},............ }

nullは無視する必要があります。

4

1 に答える 1

49
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 }
于 2009-08-25T12:50:36.333 に答える