سؤال

لدي صفيفان:

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