Pregunta

Tengo dos matrices:

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

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

Deseo devolver todas las combinaciones posibles como:

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

El nulo debe ser ignorada.

¿Fue útil?

Solución

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

Alternativamente:

from g in Group where g != null
from c in combination where c != null
select new { Group = g, Combination = c }
Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top