Question

J'ai deux tableaux:

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

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

Je veux retourner toutes les combinaisons possibles comme:

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

NULL doit être ignorée.

Était-ce utile?

La solution

Group.Where(x => x != null)
     .SelectMany(g => combination.Where(c => c != null)
                                 .Select(c => new {Group = g, Combination = c}));

Vous pouvez également:

from g in Group where g != null
from c in combination where c != null
select new { Group = g, Combination = c }
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top