두 목록에서 가능한 모든 항목 쌍을 계산 하시겠습니까?
-
19-09-2019 - |
문제
두 개의 배열이 있습니다.
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 }
제휴하지 않습니다 StackOverflow