LINQ instead of foreach and list.addrange

  • A+
Category:Languages

Does anyone knows what the Linq code is for the following code?:

foreach (Bed bed in field.GetBeds()) {     asparaguses.AddRange(bed.GetAsparaguses()); } 

 


Use SelectMany to flatten nested lists

asparaguses.AddRange(field.GetBeds().SelectMany(bed => bed.GetAsparaguses())); 

Comment

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen: