Comparing list counts with of two objects C# -


i have been sitting little problem hoping with.

i have 2 lists of modules looks follow.

what trying achieve track completed topics.

m1 represent completed set of modules skills , topics, , m2 represent topics modules, skills , topics accessed , incomplete.

list <modulea> m1; list <moduleb> m2; public class modulea {     public bool completed { get; set; }     public string modulecode { get; set; }     public list<skill> lstkeyskills { get; set; } } public class moduleb {      public string modulecode { get; set; }     public list<skill> lstkeyskills { get; set; } } public class skill {     public string keyskillname { get; set; }     public list<topic> lsttopics { get; set; } } public class topic {     public string topicname { get; set; } } 

how can topic count comparisons within skills of 2 modules?

i have tried seems messy , incorrect.

foreach (var mc in m1) {     foreach (var v in m2)     {         if (v.modulecode == mc.modulecode)         {             foreach (var skillsic in v.lstkeyskills)             {                 foreach (var skillsc in mc.lstkeyskills)                 {                     if (skillsic.lsttopics.count() == skillsc.lsttopics.count())                     {                         //count same                     }                 }             }                        }     } } 

this join, list counts match. easier in linq

var result = m1.join(m2, => a.modulecode, b => b.modulecode, (a,b) => new { = a, b = b})            .where (x => x.a.lstkeyskills.count() == x.b.lstkeyskills.count()); 

in example, result enumerable of anonymous items, has 2 properties

  • a modulea
  • b moduleb

a , b match on modulecode , have same number of skills


Comments