حساب جميع أزواج العناصر الممكنة من قائمتين؟
-
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