문제

두 개의 배열이 있습니다.

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

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

가능한 모든 조합을 반환하고 싶습니다.

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

널을 무시해야합니다.

도움이 되었습니까?

해결책

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 }
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top