c# - How to join nth list -


first of patience read such long question. shortest version, can produce far.

this question sub question of my previous question. once clarify it, update , ask reopen can answer it

my question is there practical way of nth combination of below code.

i have itinerary composed connected flights count 1,2 .. n
each flight may have classes such a, b, c ...


i combining each flight same class

here code produces combinations:

//combination of 1 flightsegments var firstflightsegments = flightsegments.where(s => s.count == 1).tolist();  var origindestination =      (from firstflightsegment in firstflightsegments     select         new origindestination {             pnr = utils.generatepnr(),             flightsegments = new list<flightsegment>{firstflightsegment}         }     ) 

//combinations of 2 flightsegments var firstflightsegments = flightsegments.where(s => s.count == 1).tolist(); var secondsecondsegments = flightsegments.where(s => s.count == 2).tolist();  var origindestination =      (from firstflightsegment in firstflightsegments         join secondflightsegment in secondsecondsegments             on firstflightsegments.flightclass equals secondsegment.flightclass     select         new origindestination {             pnr = utils.generatepnr(),             flightsegments = new list<flightsegment>{firstflightsegment, secondflightsegment}         }     ) 

//combinations of 3 flightsegments var firstflightsegments = flightsegments.where(s => s.count == 1).tolist(); var secondsecondsegments = flightsegments.where(s => s.count == 2).tolist(); var thirdflightsegments = flightsegments.where(s => s.count == 3).tolist();  var origindestination =      (from firstflightsegment in firstflightsegments         join secondflightsegment in secondsecondsegments             on firstflightsegments.flightclass equals secondsegment.flightclass                 join thirdflightsegment in thirdflightsegments                      on secondsegment.flightclass equals thirdflightsegment.flightclass             select         new origindestination {             pnr = utils.generatepnr(),             flightsegments = new list<flightsegment>{firstflightsegment, secondflightsegment, thirdflightsegment}         } 

//how combinations of n flightsegments  ??? 


edit after @rhumborl answer works fine according upper side, need add code reflect need , additional field myindex group on it

  var origindestination =            (from firstflightsegment in firstflightsegments             join secondflightsegment in secondsecondsegments                 on firstflightsegments.flightclass equals secondsegment.flightclass         select             new origindestination {                 pnr = utils.generatepnr(),                 myindex = firstflightsegment.fligthnumber + secondflightsegment.fligthnumber                 flightsegments = new list<flightsegment>{firstflightsegment, secondflightsegment}             }         ) 

it looks want flight segments flight class , return them list in order of count?

a simple groupby it:

var flights = fightsegments     .groupby(fs => fs.flightclass)  // steps each flight     .select(fc =>         new origindestination {             //flightclass = fc.key, // if need             pnr = utils.generatepnr(),             flightsegments = fc         // fc list of steps                 .orderby(s => s.count)  // make sure in order                 .tolist()         }     ) 

if want flights @ least n steps, need little more work add clause in:

var flights = fightsegments     .groupby(fs => fs.flightclass)     .where(fcg => fcg.count() >= n) // make sure flight has n+ steps     .select(fc =>         new origindestination {             //flightclass = fc.key, // if need             pnr = utils.generatepnr(),             flightsegments = fc                 .orderby(s => s.count)                 .tolist()         }     ) 

Comments

Popular posts from this blog

javascript - How to get current YouTube IDs via iMacros? -

c# - Maintaining a program folder in program files out of date? -

emulation - Android map show my location didn't work -