score:1

Accepted answer

the linq equivalent would be:

var resultset = cafedras[id - 1].specializations
                .select(s => specializations[s - 1])
                .selectmany(s => s.displinsid);

foreach(var d in resultset)
     console.writeline(disciplinas[convert.toint32(d) - 1].name);

score:2

converting nested loops does not require a join - you can do a sequence of select calls instead:

var res = cafedras[id - 1]
    .specializations
    .select(s => specializations[s - 1])
    .selectmany(s => disciplinas[convert.toint32(s.displinsid) - 1].name)
    .tolist();

above,

  • first select represents the first loop that creates specs
  • second selectmany represents the two nested loops.

this produces list<string> in the res, with subject names that could be printed.


Related Query